如何显示/隐藏菜单项,以及如何在运行时创建它吗? [英] How to Show/Hide Menu Item and how to create it at run time?

查看:108
本文介绍了如何显示/隐藏菜单项,以及如何在运行时创建它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的菜单:

<asp:Menu
        id="Menu1"
        Orientation="Horizontal"
        StaticMenuItemStyle-CssClass="tab"
        StaticSelectedStyle-CssClass="selectedTab"
        CssClass="tabs"
        OnMenuItemClick="Menu1_MenuItemClick"
        Runat="server">
        <Items>
        <asp:MenuItem Text="Tab 1" Value="0" Selected="true" />
        <asp:MenuItem Text="Tab 2" Value="1" />
        <asp:MenuItem Text="Tab 3" Value="2" />
        <asp:MenuItem Text="Tab 4" Value="3" />
        <asp:MenuItem Text="Tab 5" Value="4" />
        <asp:MenuItem Text="Tab 6" Value="5" />
        <asp:MenuItem Text="Tab 7" Value="6" />
        <asp:MenuItem Text="Tab 8" Value="7" />
        <asp:MenuItem Text="Tab 9" Value="8" />
        <asp:MenuItem Text="Tab 10" Value="9"/>
        </Items>    
    </asp:Menu>

是否有可能隐藏菜单项中的一个像说选项卡7当我点击一个按钮,并再次显示当我点击另一个按钮?我明白,我可以用RemoveAt移除,但我怎么能在这之后再次显示它?

Is it possible to hide one of the menu item like say "tab 7" when I click on a button and show it again when I click on another button? I understand that I can use "RemoveAt" but how can I show it again after that?

我想知道,以及如何在运行时创建这种菜单结构。

I want to know as well how to create this kind of menu structure at run time.

请帮我这个。

感谢您。

推荐答案

您可以使用 RemoveAt移除()办法知道你要删除的项目的索引。

You can use the RemoveAt() method knowing the index of the item you want to remove.

Menu.Items.RemoveAt(6);

有没有隐藏()方法或菜单项属性code>类。但是你可以创建一个新的实例和你的第二个按钮的Click事件过程中将其添加到菜单。

There is no Hide() method or Visible property on the MenuItem class. But you can create a new instance and add it to the menu during your second button's click event.

    MenuItem myItem = new MenuItem("Tab 7", "6");
    Menu.Items.AddAt(6, myItem);

您可以使用相同的想法,建立与code菜单:

You can use the same idea to build the menu with code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        Menu.Items.Add(new MenuItem("Tab 1", "0"));
        Menu.Items.Add(new MenuItem("Tab 2", "1"));
        ...
        Menu.Items.Add(new MenuItem("Tab 10", "9"));
    }
}

这篇关于如何显示/隐藏菜单项,以及如何在运行时创建它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆