ASP.NET newbie here. When on a page I’d like to set the corresponding menu item to selected. My approach is this:
On Home.aspx.cs:
Menu menu = (Menu)Master.FindControl("Menu1");
if (menu.Items.Count > 0)
{
menu.FindItem("Home").Selected = true;
}
Trouble is, menu.item.count == 0 .
My menu is bound to a sitemap, if that matters.
I think you must set the selected item on MenuItemDataBound event (adapt your code):
More content that shows how to handle links in a menu that has as datasource a sitemap…
To have a menu link built from web.sitemap open in new window…
In asp.net page add OnMenuItemDataBound event:
In web.sitemap, add a ? character to the url:
In code behind, capture the MenuItemDataBound event:
Any url in the web.sitemap that contains a ? will open in a new window. Note, use any other valid url character in place of the ? if necessary.
ASP.NET Menu Control Overview