I think you must set the selected item on MenuItemDataBound event (adapt your code):
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
if (SiteMap.CurrentNode != null)
{
if (e.Item.Text == SiteMap.CurrentNode.Title)
{
e.Item.Selected = true;
}
}
}
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:
<asp:Menu ID="mnuFooter" runat="server"
DataSourceID="SiteMapDataSource1"
OnMenuItemDataBound="mnuFooter_MenuItemDataBound">
</asp:Menu>
In web.sitemap, add a ? character to the url:
In code behind, capture the MenuItemDataBound event:
protected void mnuFooter_MenuItemDataBound(Object sender, MenuEventArgs e)
{
if (e.Item.NavigateUrl.Contains("?"))
{
e.Item.Target = "_blank";
}
}
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