MenuItem.ChildItems 속성

정의

현재 메뉴 항목의 하위 메뉴 항목이 들어 있는 MenuItemCollection 개체를 가져옵니다.

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

속성 값

MenuItemCollection

현재 메뉴 항목의 하위 메뉴 항목이 들어 있는 MenuItemCollection입니다. 기본값은 null이며 이 메뉴 항목에 하위 메뉴 항목이 없음을 나타냅니다.

특성

예제

다음 예제에서는 사용 하는 방법에 설명 합니다 ChildItems 속성을 트래버스하는 메뉴 항목을 Menu 컨트롤.


<%@ 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)
  {
    // If the Menu control contains any root nodes, perform a
    // preorder traversal of the tree and display the text of 
    // each node.
    if (NavigationMenu.Items.Count > 0)
    {

      // Iterate through the root menu items in the Items collection.
      foreach (MenuItem item in NavigationMenu.Items)
      {

        // Display the menu items.
        DisplayChildMenuText(item);

      }

    }
    else
    {

      Message.Text = "The Menu control does not have any items.";

    }
  }

  void DisplayChildMenuText(MenuItem item)
  {

    // Display the menu item's text value.
    Message.Text += item.Text + "<br />";

    // Iterate through the child menu items of the parent menu item 
    // passed into this method, and display their values.
    foreach (MenuItem childItem in item.ChildItems)
    {

      // Recursively call the DisplayChildMenuText method to
      // traverse the tree and display all child menu items.
      DisplayChildMenuText(childItem);

    }

  }
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu Items Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Items Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' If the Menu control contains any root nodes, perform a
    ' preorder traversal of the tree and display the text of 
    ' each node.
    If NavigationMenu.Items.Count > 0 Then
    

      ' Iterate through the root menu items in the Items collection.
      Dim item As MenuItem
      For Each item In NavigationMenu.Items

        ' Display the menu items.
        DisplayChildMenuText(item)

      Next

    Else

      Message.Text = "The Menu control does not have any items."

    End If
      
  End Sub

  Sub DisplayChildMenuText(ByVal item As MenuItem)

    ' Display the menu item's text value.
    Message.Text &= item.Text & "<br />"

    ' Iterate through the child menu items of the parent menu item 
    ' passed into this method, and display their values.
    Dim childItem As MenuItem
    For Each childItem In item.ChildItems

      ' Recursively call the DisplayChildMenuText method to
      ' traverse the tree and display all child menu items.
      DisplayChildMenuText(childItem)

    Next

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>Menu Items Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>Menu Items Example</h3>
    
      <asp:menu id="NavigationMenu"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        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>

설명

사용 된 ChildItems 있으면 현재 메뉴 항목의 하위 메뉴 항목에 액세스 하려면 속성 (컬렉션). 이 컬렉션에는 다음 수준에서 메뉴 항목만 포함 됩니다. 이상 메뉴 트리에서 아래의 메뉴 항목에 액세스 하려면 사용 된 ChildItems 후속 메뉴 항목의 속성입니다. 경우는 ChildItems 속성은 null을 현재 메뉴에 하위 메뉴 항목이 없습니다.

ChildItems 속성이 현재 메뉴 항목의 하위 메뉴 항목을 프로그래밍 방식으로 관리를 사용할 수도 있습니다. 있습니다 수 추가, 삽입, 제거, 검색 및 수정 MenuItem 컬렉션에서 개체입니다. 컬렉션에 대 한 업데이트에 자동으로 반영 됩니다는 Menu 다음에 페이지를 새로 고칠 때를 제어 합니다.

적용 대상

추가 정보