如何在System.Web.UI.WebControls.Menu中选择菜单项时传递命令参数

时间:2022-03-02 14:30:02

I have a Menu. When user clicks on the menu , I need to pass a command argument. How is that done ?

我有一个菜单。当用户单击菜单时,我需要传递一个命令参数。这是怎么做到的?

This is the code for

这是代码。

<asp:Menu ID="NoticeManagerMenu" runat="server" Orientation="Horizontal" OnMenuItemClick="NoticeManagerMenu_MenuItemClick">
            <StaticMenuStyle HorizontalPadding="0px" VerticalPadding="0px" />
            <StaticMenuItemStyle BackColor="#C0C0FF" />
            <StaticSelectedStyle BackColor="#C0C0FF" BorderColor="#C0C0FF" />
            <StaticHoverStyle BackColor="Silver" />
            <Items>
                <asp:MenuItem  Text="List"></asp:MenuItem>
                <asp:MenuItem Text="Insert"></asp:MenuItem>
            </Items>
</asp:Menu>

In the code behind, I wish to use like this

在后面的代码中,我希望这样使用

protected void NoticeManagerMenu_MenuItemClick(object sender, MenuEventArgs e)
    {
        if (e.CommandArgument.Equals("Update"))
        {


        }
        else
        {

        }           
    }

Thanks in Advance..

提前谢谢. .

2 个解决方案

#1


1  

CommandName and CommandArgument properties seem to be read-only. You might try to compare the Text of your menu item.

CommandName和CommandArgument属性似乎是只读的。您可以尝试比较菜单项的文本。

#2


0  

Did you tried Value attribute?

你试过Value属性吗?

http://msdn.microsoft.com/en-us/library/ecs0x9w5(v=VS.80).aspx

http://msdn.microsoft.com/en-us/library/ecs0x9w5(v = VS.80). aspx

#1


1  

CommandName and CommandArgument properties seem to be read-only. You might try to compare the Text of your menu item.

CommandName和CommandArgument属性似乎是只读的。您可以尝试比较菜单项的文本。

#2


0  

Did you tried Value attribute?

你试过Value属性吗?

http://msdn.microsoft.com/en-us/library/ecs0x9w5(v=VS.80).aspx

http://msdn.microsoft.com/en-us/library/ecs0x9w5(v = VS.80). aspx