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属性用于通过存储与应用对象的节点TreeNodeBinding关联的任何其他数据来补充Text该属性。 此值不显示在控件中,通常用于存储用于处理回发事件的数据。
可以通过设置ValueField属性将对象的属性TreeNode绑定到数据源的字段,而不是使用Value属性将相同的值绑定到Value每个节点。
此属性的值存储在视图状态中。
设置此属性的值可以使用设计器工具自动保存到资源文件中。 有关详细信息,请参阅LocalizableAttribute全球化和本地化。