MenuItemBinding.Value 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個非顯示值,用來儲存該物件所應用的選單項目 MenuItemBinding 的任何額外資料,例如用於處理回傳事件的資料。
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
屬性值
關於 所 MenuItemBinding 應用菜單項目的補充資料;此資料不會顯示。 預設值為空字串(“”),表示此屬性未被設定。
範例
以下程式碼範例示範如何利用該 Value 屬性指定與選單項目相關的非顯示值。 這個值會用於每個套用該物件的 MenuItemBinding 選單項目。 為了讓這個範例正確運作,你必須將下方的範例 XML 資料複製到一個名為 Menu.xml的檔案中。
<%@ page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBinding Example</h3>
<asp:menu id="NavigationMenu"
datasourceid="MenuSource"
runat="server">
<databindings>
<asp:menuitembinding datamember="MapHomeNode"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"/>
<asp:menuitembinding datamember="MapNode"
depth="1"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"/>
<asp:menuitembinding datamember="MapNode"
depth="2"
text="Static Title"
value="Static Description"
imageurl="~\Images\StaticImage.jpg"
tooltip="Static ToolTip"/>
</databindings>
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="Menu.xml"
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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>MenuItemBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>MenuItemBinding Example</h3>
<asp:menu id="NavigationMenu"
datasourceid="MenuSource"
runat="server">
<databindings>
<asp:menuitembinding datamember="MapHomeNode"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"/>
<asp:menuitembinding datamember="MapNode"
depth="1"
textfield="Title"
valuefield="Description"
imageurlfield="ImageUrl"
tooltipfield="ToolTip"/>
<asp:menuitembinding datamember="MapNode"
depth="2"
text="Static Title"
value="Static Description"
imageurl="~\Images\StaticImage.jpg"
tooltip="Static ToolTip"/>
</databindings>
</asp:menu>
<asp:xmldatasource id="MenuSource"
datafile="Menu.xml"
runat="server"/>
</form>
</body>
</html>
以下程式碼為前述範例的現場地圖範例資料。
<MapHomeNode ImageUrl="~\Images\Home.gif"
Title="Home"
Description="Root Page"
ToolTip="Home Page">
<MapNode ImageUrl="~\Images\Music.gif"
Title="Music"
Description="Music Category"
ToolTip="Music Page">
<MapNode ImageUrl="~\Images\Classical.gif"
Title="Classical"
Description="Classical Section"
ToolTip="Classical Page"/>
<MapNode ImageUrl="~\Images\Rock.gif"
Title="Rock"
Description="Rock Section"
ToolTip="Rock Page"/>
<MapNode ImageUrl="~\Images\Jazz.gif"
Title="Jazz"
Description="Jazz Section"
ToolTip="Jazz Page"/>
</MapNode>
<MapNode ImageUrl="~\Images\Movies.gif"
Title="Movies"
Description="Movies Category"
ToolTip="Movies Page">
<MapNode ImageUrl="~\Images\Action.gif"
Title="Action"
Description="Action Section"
ToolTip="Action Page"/>
<MapNode ImageUrl="~\Images\Drama.gif"
Title="Drama"
Description="Drama Section"
ToolTip="Drama Page"/>
<MapNode ImageUrl="~\Images\Musical.gif"
Title="Musical"
Description="Musical Section"
ToolTip="Musical Page"/>
</MapNode>
</MapHomeNode>
備註
當控制 Menu 項綁定到資料來源時,使用屬性 Value 指定綁定 MenuItem.Value 物件屬性 MenuItem 的值。 此值與所有套用該 MenuItemBinding 物件的選單項目共享。 指定的值不會顯示在選單項目中,而是用來儲存該物件所應用的選單項目 MenuItemBinding 的任何額外資料,例如用於處理回貼事件的資料。
Note
你可以直接設定 Value 單一選單項目的屬性來覆蓋該值。
你也可以透過設定Value該屬性,將物件的屬性MenuItem綁定ValueField到資料來源欄位,而不是用這個屬性來指定相同的選單項目。 渲染時, Value 每個套 MenuItemBinding 用該物件的選單項目屬性都會包含該欄位對應的值。
Note
若 Value 和 ValueField 性質皆為集合,則 ValueField 該性質優先。
設定後,該屬性的值可透過設計工具自動儲存到資源檔案中。 欲了解更多資訊,請參閱LocalizableAttribute全球化與在地化。