Suppose we have a asp menu like the one shown below, and we want to hide all items except the first item, the code is as follows:

<asp:Menu
        id=”MnuApplication”
        Orientation=”Horizontal”
        StaticMenuItemStyle-CssClass=”tab”
        StaticSelectedStyle-CssClass=”selectedTab”
        CssClass=”tabs”
        OnMenuItemClick=”MnuApplication_MenuItemClick”
        Runat=”server”>
        <Items>
        <asp:MenuItem Text=”Application” Value=”0″ Selected=”true” />
        <asp:MenuItem Text=”Environment” Value=”3″ />
        <asp:MenuItem Text=”Focal Point” Value=”2″ />
        <asp:MenuItem Text=”Vendor” Value=”1″ />
        </Items>   
    </asp:Menu>

There is no option to hide menu items, we have to remove them through coding, so, if we want to hide all items except the first one, that is “Application”
for (int i = 0; i < MnuApplication.Items.Count; i++)
{
    if (MnuApplication.Items.Count > 1)
    {
       if (!MnuApplication.Items[i].Text.Equals(“Application”))
        {
            MnuApplication.Items.Remove(MnuApplication.Items[i]);
            i = 0;
         }
      }
}

To add items to a menu we do the following,

MenuItem mnuVendor = new MenuItem();
mnuVendor.Text = “Vendor”;
mnuVendor.Value = “1”;
MnuApplication.Items.Add(mnuVendor);

We use views within a   multiview to display the content of each menu. we can set the index of a particular view using ActiveViewIndex on click of a menu  :

protected void MnuApplication_MenuItemClick(object sender, MenuEventArgs e)
{
  int index = Int32.Parse(e.Item.Value);
  MultiView1.ActiveViewIndex = index;
}

 

Advertisements