Reputation: 1216
How do I hide or show a menu item based on a backend condition?
Upvotes: 2
Views: 10936
Reputation: 52241
You can remove that particular menu item as follows:
MenuItem mnuItem = mnu.FindItem(""); // Find particular item
mnu.Items.Remove(mnuItem);
Upvotes: 1
Reputation: 14781
Try this:
Public Boolean Condition
{
get { ... }
}
<asp:Menu ID="..." runat="server">
<Items>
<asp:MenuItem Text="..." Value="..." Visible="<%# this.Condition %>" />
.....
</Items>
</asp:Menu>
Upvotes: 1
Reputation: 14906
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);
}
}
Upvotes: 1
Reputation: 14279
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.
Upvotes: 1