TreeNodeBinding.Value 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個未顯示的顯示值,但用於儲存該 TreeNodeBinding 物件所應用節點的額外資料,例如用於處理回傳事件的資料。
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
屬性值
關於該物件所應用節點 TreeNodeBinding 的補充資料;這些資料不會顯示。 預設為空字串(“”)。
範例
本節包含兩個程式代碼範例。 第一個程式碼範例示範如何利用該 Value 屬性儲存關於該物件所應用節點 TreeNodeBinding 的補充資料。 第二個程式碼範例提供了第一個範例的 XML 資料範例。
以下範例示範如何利用該 Value 屬性儲存關於該物件所應用節點 TreeNodeBinding 的補充資料。 為了讓此範例正常運作,您必須將範例 XML 資料複製到名為 Booklist.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>TreeViewBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeViewBinding Example</h3>
<!-- Set the Text, ImageUrl, ImageToolTip, -->
<!-- NavigateUrl, Value, and ToolTip -->
<!-- properties of a TreeNodeBinding -->
<!-- object declaratively. -->
<asp:TreeView id="BookTreeView"
DataSourceID="BookXmlDataSource"
Target="_blank"
runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="Books"
Depth="0"
TextField="Text"/>
<asp:TreeNodeBinding DataMember="Book"
Depth="1"
Text="Book Title"
ImageUrl="Image.jpg"
ImageToolTip="Book Image"
NavigateUrl="http://www.microsoft.com"
Value="BookID"
ToolTip="Book Information"/>
<asp:TreeNodeBinding DataMember="Description"
Depth="2"
TextField="Text"/>
<asp:TreeNodeBinding DataMember="Price"
Depth="2"
TextField="Value"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource id="BookXmlDataSource"
DataFile="Booklist.xml"
runat="server">
</asp:XmlDataSource>
</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>TreeViewBinding Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeViewBinding Example</h3>
<!-- Set the Text, ImageUrl, ImageToolTip, -->
<!-- NavigateUrl, Value, and ToolTip -->
<!-- properties of a TreeNodeBinding -->
<!-- object declaratively. -->
<asp:TreeView id="BookTreeView"
DataSourceID="BookXmlDataSource"
Target="_blank"
runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="Books"
Depth="0"
TextField="Text"/>
<asp:TreeNodeBinding DataMember="Book"
Depth="1"
Text="Book Title"
ImageUrl="Image.jpg"
ImageToolTip="Book Image"
NavigateUrl="http://www.microsoft.com"
Value="BookID"
ToolTip="Book Information"/>
<asp:TreeNodeBinding DataMember="Description"
Depth="2"
TextField="Text"/>
<asp:TreeNodeBinding DataMember="Price"
Depth="2"
TextField="Value"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource id="BookXmlDataSource"
DataFile="Booklist.xml"
runat="server">
</asp:XmlDataSource>
</form>
</body>
</html>
以下程式碼範例提供了前述程式碼範例的 XML 資料範例。
<Books Text="Books List">
<Book Text="Book Title One"
Value="1"
Image="Bookimage1.jpg"
ImageToolTip="Book 1 Photo"
Nav="http://www.microsoft.com"
Tip="Book Title 1">
<Description Text="Book Description">
</Description>
<Price Value="$1.99">
</Price>
<Author Text="Author Name"
Value="LastName"
Image="Authorimage1.jpg"
Nav="http://www.microsoft.com"
Tip="Author Name">
</Author>
</Book>
<Book Text="Book Title Two"
Value="2"
Image="Bookimage2.jpg"
ImageToolTip="Book 2 Photo"
Nav="http://www.microsoft.com"
Tip="Click Me">
<Description Text="Book Description">
</Description>
<Price Value="$2.99">
</Price>
<Author Text="Author Name"
Value="LastName"
Image="Authorimage2.jpg"
Nav="http://www.microsoft.com"
Tip="Author Name">
</Author>
</Book>
</Books>
備註
當控制 TreeView 項綁定到資料來源時,使用屬性 Value 指定綁定 Value 物件屬性 TreeNode 的值。 這種綁定關係影響所有 TreeNode 該物件所 TreeNodeBinding 應用的物件。 此 Value 屬性用來補充該 Text 性質,儲存與該物件所應用節點 TreeNodeBinding 相關的額外資料。 此值不會在控制項中顯示,通常用於儲存處理回傳事件的資料。
你可以不使用Value屬性綁定相同的值給每個節點,而是透過設定ValueField屬性,將物件的屬性TreeNode綁定Value到資料來源的欄位。
此屬性的價值會儲存在視圖狀態。
設定後,該屬性的值可透過設計工具自動儲存到資源檔案中。 欲了解更多資訊,請參閱LocalizableAttribute全球化與在地化。