MenuItem.Value 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個未顯示的值,用來儲存選單項目的任何額外資料,例如處理回貼事件的資料。
public:
property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };
public string Value { get; set; }
member this.Value : string with get, set
Public Property Value As String
屬性值
關於菜單項目的補充資料,未顯示。 預設值是空字串 ("")。
範例
以下範例示範如何在使用者選擇選單項目時顯示 及其 Value 父項目。
<%@ 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)
{
// Display the selected menu item.
if (e.Item.Parent != null)
{
Message.Text = "You selected " + e.Item.Value +
" from " + e.Item.Parent.Value + ".";
}
else
{
Message.Text = "You selected " + e.Item.Value + ".";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItem Value Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItem Value Example</h3>
Select an item from the menu:<br/><br/>
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
onmenuitemclick="NavigationMenu_MenuItemClick"
runat="server">
<dynamicselectedstyle backcolor="yellow"/>
<staticselectedstyle backcolor="yellow"/>
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Category"
value="Category 1"
tooltip="Category 1">
<asp:menuitem text="Topic"
value="Topic 1"
tooltip="Topic 1"/>
<asp:menuitem text="Topic"
value="Topic 2"
tooltip="Topic 2"/>
<asp:menuitem text="Topic"
value="Topic 3"
tooltip="Topic 3"/>
</asp:menuitem>
<asp:menuitem text="Category"
value="Category 2"
tooltip="Category 2">
<asp:menuitem text="Topic"
value="Topic 1"
tooltip="Topic 1"/>
<asp:menuitem text="Topic"
value="Topic 2"
tooltip="Topic 2"/>
<asp:menuitem text="Topic"
value="Topic 3"
tooltip="Topic 3"/>
</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)
' Display the selected menu item.
If e.Item.Parent IsNot Nothing Then
Message.Text = "You selected " & e.Item.Value & _
" from " & e.Item.Parent.Value & "."
Else
Message.Text = "You selected " & e.Item.Value & "."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItem Value Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItem Value Example</h3>
Select an item from the menu:<br/><br/>
<asp:menu id="NavigationMenu"
staticdisplaylevels="1"
staticsubmenuindent="10"
orientation="Vertical"
onmenuitemclick="NavigationMenu_MenuItemClick"
runat="server">
<dynamicselectedstyle backcolor="yellow"/>
<staticselectedstyle backcolor="yellow"/>
<items>
<asp:menuitem text="Home"
tooltip="Home">
<asp:menuitem text="Category"
value="Category 1"
tooltip="Category 1">
<asp:menuitem text="Topic"
value="Topic 1"
tooltip="Topic 1"/>
<asp:menuitem text="Topic"
value="Topic 2"
tooltip="Topic 2"/>
<asp:menuitem text="Topic"
value="Topic 3"
tooltip="Topic 3"/>
</asp:menuitem>
<asp:menuitem text="Category"
value="Category 2"
tooltip="Category 2">
<asp:menuitem text="Topic"
value="Topic 1"
tooltip="Topic 1"/>
<asp:menuitem text="Topic"
value="Topic 2"
tooltip="Topic 2"/>
<asp:menuitem text="Topic"
value="Topic 3"
tooltip="Topic 3"/>
</asp:menuitem>
</asp:menuitem>
</items>
</asp:menu>
<hr/>
<asp:label id="Message"
runat="server"/>
</form>
</body>
</html>
備註
Value該物業用來補充Text該物業,儲存與菜單項目相關的額外資料。 此值不會在控制項中顯示,通常用於儲存處理回傳事件的資料。
當產生屬性中ValuePath指定的值路徑時,也會使用該屬性的Value價值。 值路徑是一份以分隔符分隔的選單項目值清單,形成從根選單項目到當前選單項目的路徑。 值路徑用來指示選單項目在控制項中 Menu 的位置。
設定後,該屬性的值可透過設計工具自動儲存到資源檔案中。 欲了解更多資訊,請參閱LocalizableAttribute全球化與在地化。