MenuItemCollection.Count プロパティ
メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。
現在の MenuItemCollection オブジェクト内のメニュー項目の数を取得します。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文

Count プロパティを使用して、MenuItemCollection オブジェクト内の項目の数を確認します。通常、このプロパティは、コレクションを反復処理してコレクションの上限を確認する場合に使用されます。Count プロパティは、コレクションが空であるかどうかを確認する手段としてもよく使用されます。

Count プロパティを使用して、MenuItemCollection オブジェクト内のメニュー項目の数を確認する方法のコード例を次に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs) ' Use the Count property to determine the number of submenu ' items contained in the selected menu item. Message.Text = "The " & e.Item.Text & " menu item contains " & _ e.Item.ChildItems.Count.ToString & " submenu items." End Sub </script> <html> <body> <form runat="server"> <h3>MenuItemCollection Count Example</h3> Select an item from the menu. <br/><br/> <asp:menu id="NavigationMenu" orientation="Vertical" target="_blank" onmenuitemclick="NavigationMenu_MenuItemClick" 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="C#" %> <script runat="server"> void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e) { // Use the Count property to determine the number of submenu // items contained in the selected menu item. Message.Text = "The " + e.Item.Text + " menu item contains " + e.Item.ChildItems.Count.ToString() + " submenu items."; } </script> <html> <body> <form runat="server"> <h3>MenuItemCollection Count Example</h3> Select an item from the menu. <br/><br/> <asp:menu id="NavigationMenu" orientation="Vertical" target="_blank" onmenuitemclick="NavigationMenu_MenuItemClick" 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>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からMenuItemCollection.Count プロパティを検索する場合は、下記のリンクをクリックしてください。

- MenuItemCollection.Count プロパティのページへのリンク