0

I have a Menu control, which I fill with MainItems in code:-

  <asp:Menu ID="Menu1" runat="server" Font-Names="Calibri" Font-Size="1em" BorderColor="#CC6600" BorderStyle="Solid" BorderWidth="1px" ClientIDMode="AutoID" ForeColor="Black" OnMenuItemClick="Menu1_MenuItemClick">
    <DynamicHoverStyle BackColor="#FF9900" />
    <Items>
    <asp:MenuItem Text="Project Management" Value="Project Management">/asp:MenuItem>
    <asp:MenuItem Text="Quality" Value="Quality"></asp:MenuItem>
    <asp:MenuItem Text="Training" Value="Training"></asp:MenuItem>
    <asp:MenuItem Text="Sales" Value="Sales"></asp:MenuItem>
    <asp:MenuItem Text="Administration" Value="Administration"></asp:MenuItem>
    <asp:MenuItem Text="Maintenance" Value="Maintenance"></asp:MenuItem>
    </Items>
    </asp:Menu></td>

The Child Items are then read from a SQL table:

while (rdr.Read())
{
ThisGroup = rdr.GetInt16(0);
MenuItem homeMenuItem = new MenuItem();
MenuItem newSubMenuItem = new MenuItem();
ci.Text = (rdr.GetString(1));
ci.NavigateUrl = (rdr.GetString(2));
homeMenuItem = Menu1.Items[ThisGroup];
newSubMenuItem = new MenuItem(ci.Text, ci.NavigateUrl);
homeMenuItem.ChildItems.Add(newSubMenuItem);
}

Hovering over each menu item shows a completely unrelated URL - the same one for all items - so I debugged at the OnClick event:-

string testtext1;
string testtext2;
testtext1 = e.Item.Text;
testtext2 = e.Item.NavigateUrl;

It turns out that the e.Item.Text has the correct value, but all the NavigateUrl values are "". Can anyone spot what I've missed?

Ormond Stock
  • 37
  • 10

1 Answers1

0

The constructor MenuItem(String, String) sets the Text and Value properties of the new MenuItem. You want the Text and NavigateUrl properties set.

Instead of

newSubMenuItem = new MenuItem(ci.Text, ci.NavigateUrl);

Try

newSubMenuItem = new MenuItem(c1.Text);
newSubMenuItem.NavigateUrl = ci.NavigateUrl;
Poosh
  • 532
  • 2
  • 10
  • 25