ASP.NET Menu Control - Keeping parent item selected

前端 未结 2 1388
日久生厌
日久生厌 2021-01-26 08:14

I have two ASP.NET Menu controls on a page.

One in my header (tabs) for top level pages, e.g. ~/Default.aspx

And one in my sidebar for sub pages, e

2条回答
  •  旧时难觅i
    2021-01-26 09:21

    Figured it out with help of related question:

    Set item.selected in ASP.NET Menu Control

    protected void Page_Load(object sender, EventArgs e)
    {
        MenuControl.MenuItemDataBound += new MenuEventHandler(MenuControl_MenuItemDataBound);
    }
    
    void MenuControl_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        if (SiteMap.CurrentNode != null)
        {
            if (SiteMap.CurrentNode.ParentNode.Url == e.Item.NavigateUrl)
            {
                e.Item.Selected = true;
            }
        }
     }
    

提交回复
热议问题