MenuItem.Selected プロパティ
アセンブリ: System.Web (system.web.dll 内)

/** @property */ public boolean get_Selected () /** @property */ public void set_Selected (boolean value)
現在のメニュー項目が Menu コントロールで選択されていることを示す場合は true。それ以外の場合は false。既定値は false です。

現在のメニュー項目が選択されているかどうかを指定または確認するには、Selected プロパティを使用します。
![]() |
---|
このプロパティを使用してメニュー項目が選択されているかどうかを確認できますが、SelectedItem プロパティを使用する方がより一般的です。 |

ページが初めて読み込まれたときに、Selected プロパティを使用して、Menu コントロールの特定のメニュー項目を選択する方法のコード例を次に示します。この例を正常に動作させるには、以下のサンプル サイト マップ データを、Web.sitemap という名前のファイルにコピーする必要があります。
<%@ Page Language="VB" %> <script runat="server"> Sub NavigationMenu_MenuItemDataBound(ByVal sender As Object, ByVal e As MenuEventArgs) ' Get the menu item being bound to data. Dim item As MenuItem = e.Item ' Use the Selected property to select the Home ' menu item when the page is first loaded. If item.Text = "Home" Then item.Selected = True End If End Sub </script> <html> <body> <form runat="server"> <h3>MenuItem Selected Example</h3> <asp:menu id="NavigationMenu" staticdisplaylevels="2" staticsubmenuindent="10" orientation="Vertical" target="_blank" datasourceid="MenuSource" onmenuitemdatabound="NavigationMenu_MenuItemDataBound" runat="server"> <staticselectedstyle backcolor="Yellow"/> </asp:menu> <asp:sitemapdatasource id="MenuSource" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void NavigationMenu_MenuItemDataBound(Object sender, MenuEventArgs e) { // Get the menu item being bound to data. MenuItem item = e.Item; // Use the Selected property to select the Home // menu item when the page is first loaded. if (item.Text == "Home") { item.Selected = true; } } </script> <html> <body> <form runat="server"> <h3>MenuItem Selected Example</h3> <asp:menu id="NavigationMenu" staticdisplaylevels="2" staticsubmenuindent="10" orientation="Vertical" target="_blank" datasourceid="MenuSource" onmenuitemdatabound="NavigationMenu_MenuItemDataBound" runat="server"> <staticselectedstyle backcolor="Yellow"/> </asp:menu> <asp:sitemapdatasource id="MenuSource" runat="server"/> </form> </body> </html>
<siteMap>
<siteMapNode url="~\Home.aspx"
description="Home">
<siteMapNode url="~\Music.aspx"
description="Music">
<siteMapNode url="~\Classical.aspx"
description="Classical"/>
<siteMapNode url="~\Rock.aspx"
description="Rock"/>
<siteMapNode url="~\Jazz.aspx"
description="Jazz"/>
</siteMapNode>
<siteMapNode url="~\Movies.aspx"
<siteMapNode url="~\Action.aspx"
description="Action"/>
<siteMapNode url="~\Drama.aspx"
description="Drama"/>
<siteMapNode url="~\Musical.aspx"
description="Musical"/>
</siteMapNode>
</siteMapNode>
</siteMap>

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に収録されているすべての辞書からMenuItem.Selected プロパティを検索する場合は、下記のリンクをクリックしてください。

- MenuItem.Selected プロパティのページへのリンク