MenuEventHandler 代理人

定義

MenuItemClick コントロールの MenuItemDataBound イベントまたは Menu イベントを処理するメソッドを表します。

public delegate void MenuEventHandler(System::Object ^ sender, MenuEventArgs ^ e);
public delegate void MenuEventHandler(object sender, MenuEventArgs e);
type MenuEventHandler = delegate of obj * MenuEventArgs -> unit
Public Delegate Sub MenuEventHandler(sender As Object, e As MenuEventArgs)

パラメーター

sender
Object

イベントのソース。

e
MenuEventArgs

イベント データを格納している MenuEventArgs

次のコード例では、 デリゲートを使用して、コントロールの MenuEventHandler イベントのイベント ハンドラーをプログラムで登録する MenuItemClick 方法を Menu 示します。 この例を正しく機能させるには、以下のサンプル サイト マップ データを Web.sitemap という名前のファイルにコピーする必要があります。


<%@ 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 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 xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuEventHandler Example</title>
</head>
<body>
    <form id="form1" 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="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 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 xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuEventHandler Example</title>
</head>
<body>
    <form id="form1" 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>

<siteMapNode title="Home"

description="Home">

<siteMapNode title="Music"

description="Music">

<siteMapNode title="Classical"

description="Classical"/>

<siteMapNode title="Rock"

description="Rock"/>

<siteMapNode title="Jazz"

description="Jazz"/>

</siteMapNode>

<siteMapNode title="Movies"

description="Movies">

<siteMapNode title="Action"

description="Action"/>

<siteMapNode title="Drama"

description="Drama"/>

<siteMapNode title="Musical"

description="Musical"/>

</siteMapNode>

</siteMapNode>

</siteMap>

注釈

クラスは MenuEventHandler 、次の表のイベントを処理するメソッドを表すために使用されます。

event 説明
MenuItemClick メニュー項目がクリックされたときに発生します。 このイベントは、通常、コントロールをページ上の別の Menu コントロールと同期するために使用されます。
MenuItemDataBound メニュー項目がデータにバインドされるときに発生します。 このイベントは、通常、コントロールにレンダリングされる前にメニュー項目を Menu 変更するために使用されます。

MenuEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。 イベント ハンドラーにイベントを関連付けるには、イベントにデリゲートのインスタンスを追加します。 イベント ハンドラーは、デリゲートを削除しない限り、イベントが発生するたびに呼び出されます。 イベント ハンドラー デリゲートの詳細については、「イベントの 処理と発生」を参照してください。

拡張メソッド

GetMethodInfo(Delegate)

指定したデリゲートによって表されるメソッドを表すオブジェクトを取得します。

適用対象

こちらもご覧ください