Yogesh
Yogesh

Reputation: 1216

Conditionally hide or show Aspx Menu Control Item

How do I hide or show a menu item based on a backend condition?

Upvotes: 2

Views: 10936

Answers (4)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

You can remove that particular menu item as follows:

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

Upvotes: 1

Akram Shahda
Akram Shahda

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

Town
Town

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

Jeff
Jeff

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

Related Questions