通过


TreeNodeBinding.Text 属性

定义

获取或设置为应用对象的节点 TreeNodeBinding 显示的文本。

public:
 property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
public string Text { get; set; }
member this.Text : string with get, set
Public Property Text As String

属性值

为应用对象的节点 TreeNodeBinding 显示的文本。 默认值为空字符串(“)。

示例

本部分包含两个代码示例。 第一个代码示例演示如何使用 Text 属性指定要为应用对象的节点 TreeNodeBinding 显示的值。 第二个代码示例提供第一个代码示例的示例 XML 数据。

以下示例演示如何使用 Text 属性指定要为应用对象的节点 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 控件绑定到数据源时,使用 Text 属性指定要绑定到 Text 对象的属性 TreeNode 的值。 此绑定关系会影响应用对象的所有 TreeNode 对象 TreeNodeBinding 。 该 Text 属性用于指定在节点中显示的文本。

注释

可以通过直接设置Text每个节点的属性来选择性地替代Text属性。

可以通过设置TextField属性将对象的属性TreeNode绑定到数据源的字段,而不是使用Text属性将相同的文本绑定到Text每个节点。

此属性的值存储在视图状态中。

设置此属性的值可以使用设计器工具自动保存到资源文件中。 有关详细信息,请参阅LocalizableAttribute全球化和本地化

适用于

另请参阅