Menu.SelectedValue 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得選取功能表項目的值。
public:
property System::String ^ SelectedValue { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public string SelectedValue { get; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectedValue : string
Public ReadOnly Property SelectedValue As String
屬性值
選取功能表項目的值。 預設值為 Empty,表示目前未選取任何功能表項目。
- 屬性
範例
下列程式碼範例示範如何使用 SelectedValue 屬性來判斷控制項中 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 NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)
{
// Use the SelectedItem property to retrieve the selected
// menu item.
MenuItem selectedItem = NavigationMenu.SelectedItem;
Message.Text = "You selected " +
NavigationMenu.SelectedItem.Text + ".";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu SelectedItem Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu SelectedItem Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
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="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 NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
' Use the SelectedItem property to retrieve the selected
' menu item.
Dim selectedItem As MenuItem = NavigationMenu.SelectedItem
Message.Text = "You selected " & _
NavigationMenu.SelectedItem.Text & "."
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Menu SelectedItem Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>Menu SelectedItem Example</h3>
<asp:menu id="NavigationMenu"
staticdisplaylevels="2"
staticsubmenuindent="10"
orientation="Vertical"
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>
備註
SelectedValue使用 屬性做為快捷方式,以判斷所選功能表項目的文字。 若要存取所選功能表項目的其他屬性,請使用 SelectedItem 屬性。