MenuEventArgs.Item Proprietà

Definizione

Ottiene la voce di menu associata all'evento generato.

public:
 property System::Web::UI::WebControls::MenuItem ^ Item { System::Web::UI::WebControls::MenuItem ^ get(); };
public System.Web.UI.WebControls.MenuItem Item { get; }
member this.Item : System.Web.UI.WebControls.MenuItem
Public ReadOnly Property Item As MenuItem

Valore della proprietà

Oggetto MenuItem che rappresenta la voce di menu associata all'evento generato.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare la Item proprietà per accedere alle proprietà della voce di menu selezionata dall'utente. Il testo della voce di menu selezionata viene visualizzato nella pagina.


<%@ 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 MenuItemClick_NavigationMenu(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>MenuEventArgs Item Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuEventArgs Item Example</h3>

      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        onmenuitemclick="MenuItemClick_NavigationMenu" 
        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 MenuItemClick_NavigationMenu(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>MenuEventArgs Item Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuEventArgs Item Example</h3>

      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        onmenuitemclick="MenuItemClick_NavigationMenu" 
        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>

Commenti

Utilizzare la Item proprietà per accedere o modificare le proprietà della voce di menu associata all'evento generato. Per l'evento MenuItemClick , questa voce rappresenta la voce di menu selezionata dall'utente. Per l'evento MenuItemDataBound , questa voce rappresenta la voce di menu associata ai dati.

Si applica a

Vedi anche