Menu.SelectedValue Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar värdet för det valda menyalternativet.
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
Egenskapsvärde
Värdet för det valda menyalternativet. Standardvärdet är Empty, vilket anger att inget menyalternativ är markerat för närvarande.
- Attribut
Exempel
Följande kodexempel visar hur du använder SelectedValue egenskapen för att fastställa texten för det valda menyalternativet i en Menu kontroll.
<%@ 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>
Kommentarer
Använd egenskapen SelectedValue som en genväg för att fastställa texten i det valda menyalternativet. Om du vill komma åt de andra egenskaperna för det valda menyalternativet använder du SelectedItem egenskapen .