简体   繁体   中英

Conditionally hide or show Aspx Menu Control Item

如何根据后端条件隐藏或显示菜单项?

Found a few links. Basically it looks like this will do the trick...

MyMenu.Items(1).Visible = False

Any of those should give you what you need to hide menu items.

I think you need to remove it from the Menu:

protected void MyMenu_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        if (e.Item.Text == "Menu Item To Remove")
        {
             MyMenu.Items.Remove(e.Item);
        }
    }

Try this:

Public Boolean Condition
{
   get { ... }
}


<asp:Menu ID="..." runat="server">
  <Items>
    <asp:MenuItem Text="..." Value="..." Visible="<%# this.Condition %>" />

    .....
  </Items>
</asp:Menu>

You can remove that particular menu item as follows:

MenuItem mnuItem = mnu.FindItem(""); // Find particular item
mnu.Items.Remove(mnuItem);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM