MenuItem.Parent Eigenschaft

Definition

Ruft das übergeordnete Menüelement des aktuellen Menüelements ab.

public:
 property System::Web::UI::WebControls::MenuItem ^ Parent { System::Web::UI::WebControls::MenuItem ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Web.UI.WebControls.MenuItem Parent { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Parent : System.Web.UI.WebControls.MenuItem
Public ReadOnly Property Parent As MenuItem

Eigenschaftswert

Ein MenuItem, das das übergeordnete Menüelement des aktuellen Menüelements darstellt.

Attribute

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die Parent -Eigenschaft verwendet wird, um auf das übergeordnete Menüelement eines untergeordneten Menüelements zuzugreifen.


<%@ 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)
  {
    // Use the Parent property to access the 
    // parent menu item of the menu item clicked
    // by the user.
    MenuItem parentItem = e.Item.Parent;

    // Display the parent menu item.
    if (parentItem != null)
    {
      Message.Text = "You are in the " + parentItem.Text + 
        " category.";
    }
    else
    {
      Message.Text = "The selected menu item is a root menu item.";
    }
  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItem Parent Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItem Parent 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)
  
    ' Use the Parent property to access the 
    ' parent menu item of the menu item clicked
    ' by the user.
    Dim parentItem As MenuItem = e.Item.Parent

    ' Display the parent menu item.
    If parentItem IsNot Nothing Then

      Message.Text = "You are in the " & parentItem.Text & _
        " category."
    
    Else
    
      Message.Text = "The selected menu item is a root menu item."
      
    End If
    
  End Sub
  
</script>

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

Hinweise

Verwenden Sie die Parent -Eigenschaft, um das übergeordnete Menüelement zu bestimmen oder auf dessen Eigenschaften zuzugreifen.

Hinweis

Ein Stammmenüelement verfügt nicht über ein übergeordnetes Menüelement.

Verwenden Sie ChildItems die -Eigenschaft, um auf die Untermenüelemente des aktuellen Menüelements zuzugreifen.

Gilt für:

Weitere Informationen