MenuItemCollection 클래스

정의

Menu 컨트롤에 대한 메뉴 항목의 컬렉션을 나타냅니다. 이 클래스는 상속될 수 없습니다.

public ref class MenuItemCollection sealed : System::Collections::ICollection, System::Web::UI::IStateManager
public sealed class MenuItemCollection : System.Collections.ICollection, System.Web.UI.IStateManager
type MenuItemCollection = class
    interface ICollection
    interface IEnumerable
    interface IStateManager
Public NotInheritable Class MenuItemCollection
Implements ICollection, IStateManager
상속
MenuItemCollection
구현

예제

다음 코드 예제에서는 채우는 방법을 보여 줍니다 합니다 ItemsChildItems 선언적 구문을 사용 하 여 컬렉션입니다.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

  <!-- For the hover styles of the Menu control to  -->
  <!-- work correctly, you must include this head   -->
  <!-- element.                                     -->
  <head runat="server">
    <title>Menu Declarative Example</title>
</head>

  <body>
    <form id="form1" runat="server">
    
      <h3>Menu Declarative Example</h3>
    
      <!-- Use declarative syntax to create the   -->
      <!-- menu structure. Submenu items are      -->
      <!-- created by nesting them in parent menu -->
      <!-- items.                                 -->
      <asp:menu id="NavigationMenu"
        disappearafter="2000"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        font-names="Arial" 
        target="_blank"  
        runat="server">
        
        <staticmenuitemstyle backcolor="LightSteelBlue"
          forecolor="Black"/>
        <statichoverstyle backcolor="LightSkyBlue"/>
        <dynamicmenuitemstyle backcolor="Black"
          forecolor="Silver"/>
        <dynamichoverstyle backcolor="LightSkyBlue"
          forecolor="Black"/>
      
        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Home"
            tooltip="Home">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Movies"
              tooltip="Movies">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </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">
<html xmlns="http://www.w3.org/1999/xhtml" >

  <!-- For the hover styles of the Menu control to  -->
  <!-- work correctly, you must include this head   -->
  <!-- element.                                     -->
  <head runat="server">
    <title>Menu Declarative Example</title>
</head>

  <body>
    <form id="form1" runat="server">
    
      <h3>Menu Declarative Example</h3>
    
      <!-- Use declarative syntax to create the   -->
      <!-- menu structure. Submenu items are      -->
      <!-- created by nesting them in parent menu -->
      <!-- items.                                 -->
      <asp:menu id="NavigationMenu"
        disappearafter="2000"
        staticdisplaylevels="2"
        staticsubmenuindent="10" 
        orientation="Vertical"
        font-names="Arial" 
        target="_blank"  
        runat="server">
        
        <staticmenuitemstyle backcolor="LightSteelBlue"
          forecolor="Black"/>
        <statichoverstyle backcolor="LightSkyBlue"/>
        <dynamicmenuitemstyle backcolor="Black"
          forecolor="Silver"/>
        <dynamichoverstyle backcolor="LightSkyBlue"
          forecolor="Black"/>
      
        <items>
          <asp:menuitem navigateurl="Home.aspx" 
            text="Home"
            tooltip="Home">
            <asp:menuitem navigateurl="Music.aspx"
              text="Music"
              tooltip="Music">
              <asp:menuitem navigateurl="Classical.aspx" 
                text="Classical"
                tooltip="Classical"/>
              <asp:menuitem navigateurl="Rock.aspx"
                text="Rock"
                tooltip="Rock"/>
              <asp:menuitem navigateurl="Jazz.aspx"
                text="Jazz"
                tooltip="Jazz"/>
            </asp:menuitem>
            <asp:menuitem navigateurl="Movies.aspx"
              text="Movies"
              tooltip="Movies">
              <asp:menuitem navigateurl="Action.aspx"
                text="Action"
                tooltip="Action"/>
              <asp:menuitem navigateurl="Drama.aspx"
                text="Drama"
                tooltip="Drama"/>
              <asp:menuitem navigateurl="Musical.aspx"
                text="Musical"
                tooltip="Musical"/>
            </asp:menuitem>
          </asp:menuitem>
        </items>
      
      </asp:menu>

    </form>
  </body>
</html>

다음 코드 예제에서는 프로그래밍 방식으로 추가 하는 방법에 설명 된 MenuItem 개체를 ChildItems 루트 메뉴 항목의 컬렉션입니다.


<%@ 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 (!IsPostBack)
    {
      // Retrieve the root menu item from the Items
      // collection of the Menu control using the indexer.
      MenuItem homeMenuItem = NavigationMenu.Items[0];

      // Create the submenu item.
      MenuItem newSubMenuItem = new MenuItem("New Category");

      // Add the submenu item to the ChildItems
      // collection of the root menu item.
      homeMenuItem.ChildItems.Add(newSubMenuItem);
    }
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemCollection Add Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemCollection Add Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        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>

    </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 Not IsPostBack Then

      ' Retrieve the root menu item from the Items
      ' collection of the Menu control using the indexer.
      Dim homeMenuItem As MenuItem = NavigationMenu.Items(0)

      ' Create the submenu item.
      Dim newSubMenuItem = New MenuItem("New Category")

      ' Add the submenu item to the ChildItems
      ' collection of the root menu item.
      homeMenuItem.ChildItems.Add(newSubMenuItem)
    
    End If
      
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemCollection Add Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>MenuItemCollection Add Example</h3>
    
      <asp:menu id="NavigationMenu"
        orientation="Vertical"
        target="_blank" 
        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>

    </form>
  </body>
</html>

설명

합니다 MenuItemCollection 클래스 저장 하 고 컬렉션을 관리 하는 데 사용 됩니다 MenuItem 개체는 Menu 제어 합니다. Menu 컨트롤이 사용 하는 MenuItemCollection 루트 메뉴를 저장 하는 클래스의 항목을 Items 속성입니다. 이 컬렉션에도 사용 됩니다 합니다 ChildItems 의 속성을 MenuItem (있는 경우) 메뉴 항목의 하위 메뉴 항목을 저장할 개체입니다.

MenuItemCollection 클래스는 컬렉션의 항목에 액세스 하는 여러 방법을 지원 합니다.

  • 사용 합니다 Item[] 인덱서를 직접 검색 하는 MenuItem 특정 인덱스에 있는 개체입니다.

  • 사용 된 GetEnumerator 컬렉션을 반복 하는 데 사용할 수 있는 열거자를 만드는 방법.

  • 사용 된 CopyTo 컬렉션의 내용을 배열에 복사 하는 방법입니다.

프로그래밍 방식으로 관리할 수 있습니다는 MenuItemCollection 개체 추가 및 제거 하 여 MenuItem 개체입니다. 메뉴 항목 컬렉션에 추가 하려면 사용 합니다 Add 또는 AddAt 메서드. 컬렉션에서 노드를 제거 하려면 사용 합니다 Remove, RemoveAt, 또는 Clear 메서드.

참고

경우는 Menu 컨트롤이 데이터 소스에 바인딩되는 ItemsChildItems 컬렉션은 바인딩이 발생할 때마다 자동으로 채워집니다. 바인딩 간의 컬렉션에 모든 변경 내용이 손실 됩니다. 이러한 변경 내용을 유지 하려면 데이터 원본을 업데이트 하거나 수동으로 바인딩할 때마다 컬렉션을 다시 합니다.

MenuItemCollection 클래스 컬렉션 자체에 대 한 정보를 검색할 수 있는 메서드와 속성을 포함 합니다. 컬렉션에 있는 항목 수를 확인 하려면 사용 된 Count 속성입니다. 특정 컬렉션에 있는지 여부를 확인 하려는 경우 MenuItem 개체는 Contains 메서드. 인덱스를 가져올는 MenuItem 사용 하 여 컬렉션에서 개체를 IndexOf 메서드.

생성자

MenuItemCollection()

기본값을 사용하여 MenuItemCollection 클래스의 새 인스턴스를 초기화합니다.

MenuItemCollection(MenuItem)

지정한 부모 메뉴 항목 또는 소유자를 사용하여 MenuItemCollection 클래스의 새 인스턴스를 초기화합니다.

속성

Count

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

IsSynchronized

MenuItemCollection 개체에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지 여부를 나타내는 값을 가져옵니다.

Item[Int32]

현재 MenuItem 개체의 지정된 인덱스에 있는 MenuItemCollection 개체를 가져옵니다.

SyncRoot

MenuItemCollection 개체에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

메서드

Add(MenuItem)

지정한 MenuItem 개체를 현재 MenuItemCollection 개체의 끝에 추가합니다.

AddAt(Int32, MenuItem)

지정한 MenuItem 개체를 현재 MenuItemCollection 개체의 지정한 인덱스 위치에 삽입합니다.

Clear()

현재 MenuItemCollection 개체에서 모든 항목을 제거합니다.

Contains(MenuItem)

지정된 MenuItem 개체가 컬렉션에 있는지 여부를 확인합니다.

CopyTo(Array, Int32)

대상 배열의 지정한 인덱스부터 시작하여 MenuItemCollection 개체의 모든 항목을 호환되는 1차원 Array에 복사합니다.

CopyTo(MenuItem[], Int32)

대상 배열의 지정한 인덱스부터 시작하여 MenuItemCollection 개체의 모든 항목을 MenuItem 개체의 호환되는 1차원 배열에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

현재 MenuItemCollection 개체의 항목을 반복하는 데 사용할 수 있는 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IndexOf(MenuItem)

컬렉션에서 지정된 MenuItem 개체의 인덱스를 확인합니다.

MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove(MenuItem)

MenuItem 개체에서 지정한 MenuItemCollection 개체를 제거합니다.

RemoveAt(Int32)

현재 MenuItem 개체의 지정된 인덱스 위치에서 MenuItemCollection 개체를 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IStateManager.IsTrackingViewState

MenuItemCollection 개체에서 해당 뷰 상태의 변경 내용을 저장하는지 여부를 나타내는 값을 가져옵니다.

IStateManager.LoadViewState(Object)

이전에 저장된 MenuItemCollection 개체의 뷰 상태를 로드합니다.

IStateManager.SaveViewState()

뷰 상태 변경 내용을 Object에 저장합니다.

IStateManager.TrackViewState()

MenuItemCollection 개체에서 해당 뷰 상태의 변경 내용을 추적하도록 합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보