MenuEventHandler デリゲート
アセンブリ: System.Web (system.web.dll 内)


MenuEventHandler クラスは、次の表に示すイベントを処理するメソッドを表すために使用されます。
MenuItemClick | メニュー項目がクリックされると発生します。通常このイベントは、Menu コントロールをページ上の別のコントロールと同期する場合に使用されます。 |
MenuItemDataBound | メニュー項目がデータにバインドされると発生します。通常このイベントは、メニュー項目が Menu コントロールに表示される前にメニュー項目を変更する場合に使用されます。 |
MenuEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを識別してください。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「イベントとデリゲート」を参照してください。

MenuEventHandler デリゲートを使用して、Menu コントロールの MenuItemClick イベントのイベント ハンドラをプログラムによって登録する方法のコード例を次に示します。この例を正常に動作させるには、以下のサンプル サイト マップ データを、Web.sitemap という名前のファイルにコピーする必要があります。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new Menu control. Dim newMenu As New Menu() ' Set the properties of the Menu control. newMenu.ID = "NavigationMenu" newMenu.Orientation = Orientation.Vertical newMenu.Target = "_blank" ' Specify the data source for the menu. newMenu.DataSourceID = "MenuSource" ' Programmatically register the event-handling method ' for the MenuItemClick event of a Menu control. AddHandler newMenu.MenuItemClick, AddressOf NavigationMenu_MenuItemClick ' Add the Menu control to the Controls collection ' of the PlaceHolder control. MenuPlaceHolder.Controls.Add(newMenu) End Sub 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> <body> <form runat="server"> <h3>MenuEventHandler Example</h3> <asp:placeholder id="MenuPlaceHolder" runat="server"/> <asp:sitemapdatasource id="MenuSource" runat="server"/> <hr/> <asp:label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Create a new Menu control. Menu newMenu = new Menu(); // Set the properties of the Menu control. newMenu.ID = "NavigationMenu"; newMenu.Orientation = Orientation.Vertical; newMenu.Target = "_blank"; // Specify the data source for the menu. newMenu.DataSourceID = "MenuSource"; // Programmatically register the event-handling method // for the MenuItemClick event of a Menu control. newMenu.MenuItemClick += new MenuEventHandler(this.NavigationMenu_MenuItemClick); // Add the Menu control to the Controls collection // of the PlaceHolder control. MenuPlaceHolder.Controls.Add(newMenu); } 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> <body> <form runat="server"> <h3>MenuEventHandler Example</h3> <asp:placeholder id="MenuPlaceHolder" runat="server"/> <asp:sitemapdatasource id="MenuSource" runat="server"/> <hr/> <asp:label id="Message" runat="server"/> </form> </body> </html>
<siteMap>
description="Home">
description="Music">
<siteMapNode title="Classical"
description="Classical"/>
description="Rock"/>
description="Jazz"/>
</siteMapNode>
description="Action"/>
description="Drama"/>
description="Musical"/>
</siteMapNode>
</siteMapNode>
</siteMap>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- MenuEventHandler デリゲートのページへのリンク