Menu.MenuItemClick 活動
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當點擊控制項中的 Menu 選單項目時會發生。
public:
event System::Web::UI::WebControls::MenuEventHandler ^ MenuItemClick;
public event System.Web.UI.WebControls.MenuEventHandler MenuItemClick;
member this.MenuItemClick : System.Web.UI.WebControls.MenuEventHandler
Public Custom Event MenuItemClick As MenuEventHandler
事件類型
範例
以下程式碼範例示範如何建立事件處理 MenuItemClick 程序,顯示使用者所選選單項目的文字。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
{
// Display the text of the menu item selected by the user.
Message.Text = "You selected " +
e.Item.Text + ".";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu MenuItemClick Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu MenuItemClick Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
onmenuitemclick="NavigationMenu_MenuItemClick"
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
' Display the text of the menu item selected by the user.
Message.Text = "You selected " & _
e.Item.Text & "."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu MenuItemClick Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu MenuItemClick Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
onmenuitemclick="NavigationMenu_MenuItemClick"
runat="server">
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Music"
tooltip="Music">
<asp:menuitem text="Classical"
tooltip="Classical"/>
<asp:menuitem text="Rock"
tooltip="Rock"/>
<asp:menuitem text="Jazz"
tooltip="Jazz"/>
</asp:menuitem>
<asp:menuitem text="Movies"
tooltip="Movies">
<asp:menuitem text="Action"
tooltip="Action"/>
<asp:menuitem text="Drama"
tooltip="Drama"/>
<asp:menuitem text="Musical"
tooltip="Musical"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
備註
當控制項中點擊MenuItemClick選單項目時,事件Menu會被觸發。 這讓你能提供一個事件處理器,當事件發生時執行自訂例程,例如與頁面上的另一個控制項同步。
一個 MenuEventArgs 物件會傳給事件處理器,讓你能存取引發事件的選單項目屬性。
欲了解更多如何處理事件的資訊,請參閱 「處理與提升事件」。