TreeView 类

定义

在树结构中显示分层数据,例如目录。Displays hierarchical data, such as a table of contents, in a tree structure.

public ref class TreeView : System::Web::UI::WebControls::HierarchicalDataBoundControl, System::Web::UI::ICallbackEventHandler, System::Web::UI::IPostBackDataHandler, System::Web::UI::IPostBackEventHandler
[System.Web.UI.ControlValueProperty("SelectedValue")]
public class TreeView : System.Web.UI.WebControls.HierarchicalDataBoundControl, System.Web.UI.ICallbackEventHandler, System.Web.UI.IPostBackDataHandler, System.Web.UI.IPostBackEventHandler
type TreeView = class
    inherit HierarchicalDataBoundControl
    interface IPostBackEventHandler
    interface IPostBackDataHandler
    interface ICallbackEventHandler
Public Class TreeView
Inherits HierarchicalDataBoundControl
Implements ICallbackEventHandler, IPostBackDataHandler, IPostBackEventHandler
继承
属性
实现

示例

本部分包含七个代码示例:This section contains seven code examples:

  • 第一个代码示例演示如何为第二个代码示例设置帧。The first code example demonstrates how to set up the frames for the second code example.

  • 第二个代码示例演示如何使用声明性语法在TreeView控件中显示静态数据。The second code example demonstrates how to use declarative syntax to display static data in the TreeView control.

  • 第三个代码示例演示如何将TreeView控件绑定到 XML 数据源。The third code example demonstrates how to bind the TreeView control to an XML data source.

  • 第四个代码示例提供了第三个代码示例的示例 XML 数据。The fourth code example provides sample XML data for the third code example.

  • 第五个代码示例演示如何通过将TreeView控件绑定SiteMapDataSource到控件来使用控件进行站点导航。The fifth code example demonstrates how to use the TreeView control for site navigation by binding it to a SiteMapDataSource control.

  • 第六个代码示例提供了第五个代码示例的示例站点地图数据。The sixth code example provides sample site map data for the fifth code example.

  • 第七个代码示例演示如何从客户端填充TreeView控件中的节点。The seventh code example demonstrates how to populate the nodes in the TreeView control from the client.

下面的代码示例演示如何为以下代码示例设置帧。The following code example demonstrates how to set up the frames for the following code example.


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>TreeView Frameset Example</title>
</head>
         
    <frameset cols="30%, 75%">
   
        <frame title="MenuFrame" name="Menu" src="TreeViewFramecs.aspx"/>
        <frame title="ContentFrame" name="Content" src="Home.aspx"/> 
           
    </frameset>      
   
</html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>TreeView Frameset Example</title>
</head>
         
    <frameset cols="30%, 75%">
   
        <frame title="MenuFrame" name="Menu" src="TreeViewFramevb.aspx"/>
        <frame title="ContentFrame" name="Content" src="Home.aspx"/> 
           
    </frameset>      
   
</html>

下面的代码示例演示如何使用声明性语法在TreeView控件中显示静态数据。The following code example demonstrates how to use declarative syntax to display static data in the TreeView control. 此示例在前面示例的帧集中用于显示目录。This example is used within the frame set of the preceding example to display a table of contents.


<%@ 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>TreeView Declarative Syntax Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView Declarative Syntax Example</h3>
      
      <asp:TreeView id="SampleTreeView" 
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </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>TreeView Declarative Syntax Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView Declarative Syntax Example</h3>
      
      <asp:TreeView id="SampleTreeView" 
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Home" 
            NavigateUrl="Home.aspx" 
            Text="Home"
            Target="Content" 
            Expanded="True">
             
            <asp:TreeNode Value="Page 1" 
              NavigateUrl="Page1.aspx" 
              Text="Page1"
              Target="Content">
               
              <asp:TreeNode Value="Section 1" 
                NavigateUrl="Section1.aspx" 
                Text="Section 1"
                Target="Content"/>
                 
            </asp:TreeNode>              
            
            <asp:TreeNode Value="Page 2" 
              NavigateUrl="Page2.aspx"
              Text="Page 2"
              Target="Content">
               
            </asp:TreeNode> 
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>

    </form>
  </body>
</html>

下面的代码示例演示如何将TreeView控件绑定到 XML 数据源。The following code example demonstrates how to bind the TreeView control to an XML data source. 若要使此示例正常工作, 必须将示例 XML 数据 (在此代码示例之后提供) 复制到名为 books.xml 的文件中。For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named Book.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>TreeView XML Data Binding Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView XML Data Binding Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.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>TreeView XML Data Binding Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView XML Data Binding Example</h3>
    
      <asp:TreeView id="BookTreeView" 
        DataSourceID="BookXmlDataSource"
        runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" TextField="Heading"/>
        </DataBindings>
         
      </asp:TreeView>

      <asp:XmlDataSource id="BookXmlDataSource"  
        DataFile="Book.xml"
        runat="server">
      </asp:XmlDataSource>
    
    </form>
  </body>
</html>

下面的代码示例提供了前面示例的示例 XML 数据。The following code example provides sample XML data for the preceding example.

<Book Title="Book Title">  
    <Chapter Heading="Chapter 1">  
        <Section Heading="Section 1">  
        </Section>  
        <Section Heading="Section 2">  
        </Section>  
    </Chapter>  
    <Chapter Heading="Chapter 2">  
        <Section Heading="Section 1">  
        </Section>  
    </Chapter>  
</Book>  

下面的代码示例演示如何通过将TreeView控件绑定SiteMapDataSource到控件来使用控件进行站点导航。The following code example demonstrates how to use the TreeView control for site navigation by binding it to a SiteMapDataSource control. 若要使此示例正常工作, 您必须将示例站点地图数据 (在此代码示例之后提供) 复制到名为 "web.sitemap" 的文件中。For this example to work correctly, you must copy the sample site map data, provided after this code example, to a file named Web.sitemap.


<%@ 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>TreeView AutoGenerateBindings Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView AutoGenerateBindings Example</h3>
    
      <!-- Set the AutoGenerateBindings property -->
      <!-- to false declaratively to allow for   -->
      <!-- the user-defined Bindings collection. -->
      <asp:TreeView id="SiteTreeView" 
        DataSourceID="SiteMapSource"
        AutoGenerateDataBindings="False"
        runat="server">
        
        <DataBindings>
        
          <asp:TreeNodeBinding TextField="title" NavigateUrlField="url"/>
        
        </DataBindings>
            
      </asp:TreeView>
      
      <asp:SiteMapDataSource ID="SiteMapSource" 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>TreeView AutoGenerateBindings Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView AutoGenerateBindings Example</h3>
    
      <!-- Set the AutoGenerateBindings property -->
      <!-- to false declaratively to allow for   -->
      <!-- the user-defined Bindings collection. -->
      <asp:TreeView id="SiteTreeView" 
        DataSourceID="SiteMapSource"
        AutoGenerateDataBindings="False"
        runat="server">
        
        <DataBindings>
        
          <asp:TreeNodeBinding TextField="title" NavigateUrlField="url"/>
        
        </DataBindings>
            
      </asp:TreeView>
      
      <asp:SiteMapDataSource ID="SiteMapSource" runat="server"/>
         
    </form>
  </body>
</html>

下面的代码示例提供了前面的代码示例的示例站点地图数据。The following code example provides sample site map data for the preceding code example.

<siteMap>  
    <siteMapNode title="Home" description="Home" url="default.aspx">  
        <siteMapNode title="Products" description="Products" url="Products.aspx">  
            <siteMapNode title="Computers" url="Computers.aspx"/>  
            <siteMapNode title="Accessories" url="Accessories.aspx"/>       
        </siteMapNode>  
    </siteMapNode>  
</siteMap>  

下面的代码示例演示如何从客户端填充TreeView控件中的节点。The following code example demonstrates how to populate the nodes in the TreeView control from the client. 启用客户端节点填充后, 节点会在客户端上动态填充, 而无需回发到服务器。When client-side node population is enabled, nodes are populated dynamically on the client, without the need to post back to the server.


<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void PopulateNode(Object sender, TreeNodeEventArgs e)
  {

    // Call the appropriate method to populate a node at a particular level.
    switch(e.Node.Depth)
    {
      case 0:
        // Populate the first-level nodes.
        PopulateCategories(e.Node);
        break;
      case 1:
        // Populate the second-level nodes.
        PopulateProducts(e.Node);
        break;
      default:
        // Do nothing.
        break;
    }
    
  }

  void PopulateCategories(TreeNode node)
  {
    
    // Query for the product categories. These are the values
    // for the second-level nodes.
    DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories");

    // Create the second-level nodes.
    if(ResultSet.Tables.Count > 0)
    {
    
      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {
        
        // Create the new node. Notice that the CategoryId is stored in the Value property 
        // of the node. This will make querying for items in a specific category easier when
        // the third-level nodes are created. 
        TreeNode newNode = new TreeNode();
        newNode.Text = row["CategoryName"].ToString(); 
        newNode.Value = row["CategoryID"].ToString();        

        // Set the PopulateOnDemand property to true so that the child nodes can be 
        // dynamically populated.
        newNode.PopulateOnDemand = true;
        
        // Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand;
        
        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode);
        
      }
      
    }
    
  }

  void PopulateProducts(TreeNode node)
  {

    // Query for the products of the current category. These are the values
    // for the third-level nodes.
    DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value);

    // Create the third-level nodes.
    if(ResultSet.Tables.Count > 0)
    {
    
      // Iterate through and create a new node for each row in the query results.
      // Notice that the query results are stored in the table of the DataSet.
      foreach (DataRow row in ResultSet.Tables[0].Rows)
      {
      
        // Create the new node.
        TreeNode NewNode = new TreeNode(row["ProductName"].ToString());
        
        // Set the PopulateOnDemand property to false, because these are leaf nodes and
        // do not need to be populated.
        NewNode.PopulateOnDemand = false;
        
        // Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None;
        
        // Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode);
        
      }
      
    }

  }

  DataSet RunQuery(String QueryString)
  {

    // Declare the connection string. This example uses Microsoft SQL Server 
    // and connects to the Northwind sample database.
    String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI"; 

    SqlConnection DBConnection = new SqlConnection(ConnectionString);
    SqlDataAdapter DBAdapter;
    DataSet ResultsDataSet = new DataSet();

    try
    {

      // Run the query and create a DataSet.
      DBAdapter = new SqlDataAdapter(QueryString, DBConnection);
      DBAdapter.Fill(ResultsDataSet);

      // Close the database connection.
      DBConnection.Close();

    }
    catch(Exception ex)
    {

      // Close the database connection if it is still open.
      if(DBConnection.State == ConnectionState.Open)
      {
        DBConnection.Close();
      }
      
      Message.Text = "Unable to connect to the database.";

    }

    return ResultsDataSet;

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PopulateNodesFromClient Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br /><br />
      
      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>


<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs)

    ' Call the appropriate method to populate a node at a particular level.
    Select Case e.Node.Depth

      Case 0
        ' Populate the first-level nodes.
        PopulateCategories(e.Node)

      Case 1
        ' Populate the second-level nodes.
        PopulateProducts(e.Node)

      Case Else
        ' Do nothing.

    End Select

  End Sub

  Sub PopulateCategories(ByVal node As TreeNode)

    ' Query for the product categories. These are the values
    ' for the second-level nodes.
    Dim ResultSet As DataSet = RunQuery("Select CategoryID, CategoryName From Categories")

    ' Create the second-level nodes.
    If ResultSet.Tables.Count > 0 Then

      ' Iterate through and create a new node for each row in the query results.
      ' Notice that the query results are stored in the table of the DataSet.
      Dim row As DataRow

      For Each row In ResultSet.Tables(0).Rows

        ' Create the new node. Notice that the CategoryId is stored in the Value property 
        ' of the node. This will make querying for items in a specific category easier when
        ' the third-level nodes are created. 
        Dim newNode As TreeNode = New TreeNode()
        Newnode.Text = row("CategoryName").ToString() 
        Newnode.Value = row("CategoryID").ToString()

        ' Set the PopulateOnDemand property to true so that the child nodes can be 
        ' dynamically populated.
        newNode.PopulateOnDemand = True

        ' Set additional properties for the node.
        newNode.SelectAction = TreeNodeSelectAction.Expand

        ' Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(newNode)

      Next

    End If

  End Sub

  Sub PopulateProducts(ByVal node As TreeNode)

    ' Query for the products of the current category. These are the values
    ' for the third-level nodes.
    Dim ResultSet As DataSet = RunQuery("Select ProductName From Products Where CategoryID=" & node.Value)

    ' Create the third-level nodes.
    If ResultSet.Tables.Count > 0 Then

      ' Iterate through and create a new node for each row in the query results.
      ' Notice that the query results are stored in the table of the DataSet.
      Dim row As DataRow

      For Each row In ResultSet.Tables(0).Rows

        ' Create the new node.
        Dim NewNode As TreeNode = New TreeNode(row("ProductName").ToString())

        ' Set the PopulateOnDemand property to false, because these are leaf nodes and
        ' do not need to be populated.
        NewNode.PopulateOnDemand = False

        ' Set additional properties for the node.
        NewNode.SelectAction = TreeNodeSelectAction.None

        ' Add the new node to the ChildNodes collection of the parent node.
        node.ChildNodes.Add(NewNode)

      Next

    End If

  End Sub

  Function RunQuery(ByVal QueryString As String) As DataSet

    ' Declare the connection string. This example uses Microsoft SQL Server 
    ' and connects to the Northwind sample database.
    Dim ConnectionString As String = "server=localhost;database=NorthWind;Integrated Security=SSPI"

    Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString)
    Dim DBAdapter As SqlDataAdapter
    Dim ResultsDataSet As DataSet = New DataSet

    Try

      ' Run the query and create a DataSet.
      DBAdapter = New SqlDataAdapter(QueryString, DBConnection)
      DBAdapter.Fill(ResultsDataSet)

      ' Close the database connection.
      DBConnection.Close()

    Catch ex As Exception

      ' Close the database connection if it is still open.
      If DBConnection.State = ConnectionState.Open Then

        DBConnection.Close()

      End If

      Message.Text = "Unable to connect to the database."

    End Try

    Return ResultsDataSet

  End Function

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeView PopulateNodesFromClient Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PopulateNodesFromClient Example</h3>
    
      <asp:TreeView id="LinksTreeView"
        Font-Names= "Arial"
        ForeColor="Blue"
        EnableClientScript="true"
        PopulateNodesFromClient="true"  
        OnTreeNodePopulate="PopulateNode"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Text="Inventory" 
            SelectAction="Expand"  
            PopulateOnDemand="true"/>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br /><br />
      
      <asp:Label id="Message" runat="server"/>

    </form>
  </body>
</html>

注解

本主题内容:In this topic:

介绍Introduction

TreeView控件用于在树结构中显示分层数据, 例如目录或文件目录, 并支持以下功能:The TreeView control is used to display hierarchical data, such as a table of contents or file directory, in a tree structure and supports the following features:

  • 允许控件的节点绑定到 XML、表格或关系数据的数据绑定。Data binding that allows the nodes of the control to be bound to XML, tabular, or relational data.

  • 通过与SiteMapDataSource控件集成的站点导航。Site navigation through integration with the SiteMapDataSource control.

  • 可以显示为纯文本或超链接的节点文本。Node text that can be displayed as either plain text or hyperlinks.

  • 以编程方式访问TreeView对象模型, 以动态方式创建树、填充节点、设置属性等。Programmatic access to the TreeView object model to create trees, populate nodes, set properties, and so on dynamically.

  • 客户端节点填充 (在支持的浏览器上)。Client-side node population (on supported browsers).

  • 能够在每个节点旁边显示复选框。The ability to display a check box next to each node.

  • 通过主题、用户定义图像和样式自定义外观。Customizable appearance through themes, user-defined images, and styles.

    备注

    控件设计为仅在设置为trueEnableClientScriptUpdatePanel控件内使用。 TreeViewThe TreeView control is designed to be used inside an UpdatePanel control only when EnableClientScript is set to true. UpdatePanel控件用于更新页面的选定区域, 而不是使用回发来更新整个页面。UpdatePanel controls are used to update selected regions of a page instead of updating the whole page with a postback. 有关详细信息, 请参阅UpdatePanel 控件概述部分页呈现概述For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.

节点Nodes

TreeView控件由节点组成。The TreeView control is made up of nodes. 树中的每个条目称为节点, 由TreeNode对象表示。Each entry in the tree is called a node and is represented by a TreeNode object. 节点类型定义如下:Node types are defined as follows:

  • 包含其他节点的节点称为父节点A node that contains other nodes is called a parent node.

  • 其他节点包含的节点称为子节点The node that is contained by another node is called a child node.

  • 没有子项的节点称为叶节点A node that has no children is called a leaf node.

  • 不是由任何其他节点包含的节点, 而是其他所有节点的上级节点。 The node that is not contained by any other node but is the ancestor to all the other nodes is the root node.

节点可以是父节点和子节点, 但根节点、父节点和叶节点都是互斥的。A node can be both a parent and a child, but root, parent, and leaf nodes are mutually exclusive. 节点的多个视觉和行为属性由节点是根节点、子节点还是叶节点确定。Several visual and behavioral properties of nodes are determined by whether a node is a root, child, or leaf node.

尽管典型树结构只有一个根节点, 但该TreeView控件允许您将多个根节点添加到树结构。Although a typical tree structure has only one root node, the TreeView control allows you to add multiple root nodes to your tree structure. 如果希望在不显示单个根节点的情况下显示项列表, 则这非常有用, 如在产品类别列表中。This is useful when you want to display item listings without displaying a single root node, as in a list of product categories.

每个节点都Text有一个属性Value和一个属性。Each node has a Text property and a Value property. Text属性的值TreeView在中显示, 而Value属性用于存储关于节点的任何其他数据, 如传递到与节点相关联的回发事件的数据。The value of the Text property is displayed in the TreeView, while the Value property is used to store any additional data about the node, such as data that is passed to the postback event that is associated with the node.

节点可以是以下两种模式之一: 选择模式和导航模式。A node can be in one of two modes: selection mode and navigation mode. 默认情况下, 节点处于选择模式。By default, a node is in selection mode. 若要使节点进入导航模式, 请将NavigateUrl节点的属性设置为空字符串 ("") 以外的值。To put a node into navigation mode, set the NavigateUrl property for the node to a value other than an empty string (""). 若要将节点置于选择模式, 请将NavigateUrl节点的属性设置为空字符串 ("")。To put a node into selection mode, set the NavigateUrl property for the node to an empty string ("").

备注

某些 Internet 浏览器有可能会影响TreeView控件性能的限制。Some Internet browsers have a limitation that can affect the performance of the TreeView control. 例如, Microsoft Internet Explorer 6.0 的 URL 字符限制为2067个字符。For example, Microsoft Internet Explorer 6.0 has a URL character limit of 2067 characters that it posts. 如果节点 URL 中的字符数大于该数量, 则展开该节点将失败, 并且不会引发异常。If the number of characters in a URL of a node is larger than that number, expanding that node will fail and no exception is thrown.

静态数据Static Data

TreeView控件的最简单数据模型为静态数据。The simplest data model of the TreeView control is static data. 若要使用声明性语法显示静态数据, 请先在<Nodes> TreeView控件的开始和结束标记之间嵌套开始和结束标记。To display static data using declarative syntax, first nest opening and closing <Nodes> tags between the opening and closing tags of the TreeView control. 接下来, 通过在开始和结束<asp:TreeNode> <Nodes>标记之间嵌套元素来创建树结构。Next, create the tree structure by nesting <asp:TreeNode> elements between the opening and closing <Nodes> tags. <asp:TreeNode>个元素都表示树中的一个节点并映射TreeNode到一个对象。Each <asp:TreeNode> element represents a node in the tree and maps to a TreeNode object. 可以通过设置每个节点的<asp:TreeNode>元素的属性来设置这些属性。You can set the properties of each node by setting the attributes of its <asp:TreeNode> element. 若要创建子节点, 请<asp:TreeNode>在父节点的开始标记<asp:TreeNode>和结束标记之间嵌套其他元素。To create child nodes, nest additional <asp:TreeNode> elements between the opening and closing <asp:TreeNode> tags of the parent node.

绑定到数据Binding to Data

还可以将控件绑定到数据。 TreeViewThe TreeView control can also be bound to data. 您可以使用两种方法中的任意一TreeView种将控件绑定到相应的数据源类型:You can use either of two methods to bind the TreeView control to the appropriate data source type:

绑定到数据源 (其中每个数据项都包含多个属性) 时, 默认情况下, 节点将显示数据项的ToString方法返回的值。When binding to a data source where each data item contains multiple properties (such as an XML element with several attributes), a node displays the value that is returned by the ToString method of the data item, by default. 对于 XML 元素, 该节点将显示元素名称, 该名称显示树的基础结构, 但在其他情况下不起作用。In the case of an XML element, the node displays the element name, which shows the underlying structure of the tree but is not very useful otherwise. 您可以通过使用DataBindings集合指定树节点绑定, 将节点绑定到特定数据项属性。You can bind a node to a specific data item property by specifying tree node bindings using the DataBindings collection. DataBindings集合包含TreeNodeBinding的对象定义数据项和它所绑定到的节点之间的关系。The DataBindings collection contains TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to. 您可以指定要在节点中显示的绑定条件和数据项属性。You can specify the criteria for binding and the data item property to display in the node. 有关树节点绑定的详细信息, 请TreeNodeBinding参阅。For more information on tree node bindings, see TreeNodeBinding.

重要

恶意用户可以创建回调请求并获取页面开发人员未显示的TreeView控件节点的数据。A malicious user can create a callback request and get data for the nodes of the TreeView control that the page developer is not displaying. 因此, 数据的安全必须由数据源实现。Therefore, security of the data must be implemented by the data source. 不要使用MaxDataBindDepth属性来隐藏数据。Do not use the MaxDataBindDepth property to hide data.

动态节点填充Dynamic Node Population

有时, 静态定义树结构是不切实际的, 因为数据源返回太多数据, 或是因为要显示的数据取决于您在运行时获取的信息。Sometimes, it is not practical to statically define the tree structure because the data source returns too much data or because the data to display depends on information that you get at run time. 因此, TreeView控件支持动态节点填充。Because of this, the TreeView control supports dynamic node population. 如果将PopulateOnDemand节点的属性设置为true, 则在展开节点时, 将在运行时填充该节点。When the PopulateOnDemand property for a node is set to true, that node gets populated at run time when the node is expanded. 若要动态填充节点, 必须定义一个事件处理方法, 其中包含用于填充TreeNodePopulate事件节点的逻辑。To populate a node dynamically, you must define an event-handling method that contains the logic to populate a node for the TreeNodePopulate event.

支持回调脚本的浏览器还可利用客户端节点填充。Browsers that support callback scripts can also take advantage of client-side node population. (这包括 Internet Explorer 5.5 和更高版本以及其他一些浏览器。)客户端节点填充使TreeView控件能够在用户展开节点时使用客户端脚本填充节点, 而无需往返服务器。(This includes Internet Explorer 5.5 and later and some other browsers.) Client-side node population enables the TreeView control to populate a node using client script when users expand the node, without requiring a round trip to the server. 有关客户端节点填充的详细信息, 请参阅PopulateNodesFromClientFor more information on client-side node population, see PopulateNodesFromClient.

自定义用户界面Customizing the User Interface

可以通过多种方式自定义TreeView控件的外观。There are many ways to customize the appearance of the TreeView control. 首先, 您可以为每个节点类型指定不同的样式 (如字体大小和颜色)。First, you can specify a different style (such as font size and color) for each of the node types.

如果使用级联样式表 (CSS) 来自定义控件的外观, 则可以使用内联样式或单独的 CSS 文件, 但不能同时使用两者。If you use cascading style sheets (CSS) to customize the appearance of the control, use either inline styles or a separate CSS file, but not both. 同时使用内联样式和单独的 CSS 文件可能导致意外的结果。Using both inline styles and a separate CSS file could cause unexpected results. 有关将样式表用于控件的详细信息, 请参阅Web 服务器控件和 CSS 样式For more information on using style sheets with controls, see Web Server Controls and CSS Styles.

下表列出了可用的节点样式。The following table lists the available node styles.

节点样式属性Node style property 说明Description
HoverNodeStyle 当鼠标指针位于节点上时该节点的样式设置。The style settings for a node when the mouse pointer is positioned over it.
LeafNodeStyle 叶节点的样式设置。The style settings for the leaf nodes.
NodeStyle 节点的默认样式设置。The default style settings for a node.
ParentNodeStyle 父节点的样式设置。The style settings for the parent nodes.
RootNodeStyle 根节点的样式设置。The style settings for the root node.
SelectedNodeStyle 所选节点的样式设置。The style settings for a selected node.

你还可以使用LevelStyles集合来控制树中特定深度的节点的样式。You can also control the style of nodes at specific depths within the tree by using the LevelStyles collection. 集合中的第一种样式对应于树中第一级节点的样式。The first style in the collection corresponds to the style of the nodes at the first level in the tree. 集合中的第二个样式与树中第二级节点上的节点样式相对应, 依此类推。The second style in the collection corresponds to the style of the nodes at the second level in the tree, and so on. 这通常用于生成目录样式的导航菜单, 其中, 特定深度的节点应具有相同的外观, 而不考虑它们是否具有子节点。This is most often used to generate table of contents-style navigation menus where nodes at a certain depth should have the same appearance, regardless of whether they have child nodes.

备注

如果使用LevelStyles集合为某个深度级别定义了样式, 则该样式会重写该深度节点的任何根节点、父节点或叶节点样式设置。If a style is defined for a certain depth level using the LevelStyles collection, that style overrides any root, parent, or leaf node style settings for the nodes at that depth.

更改控件外观的另一种方法是自定义TreeView控件中显示的图像。Another way to alter the appearance of the control is to customize the images that are displayed in the TreeView control. 您可以通过设置下表中显示的属性, 为控件的不同部分指定您自己的自定义图像集。You can specify your own custom set of images for the different parts of the control by setting the properties shown in the following table.

Image 属性Image property 说明Description
CollapseImageUrl 可折叠节点的指示符所显示图像的 URL。The URL to an image displayed for the collapsible node indicator. 此图像通常为减号 (-)。This image is usually a minus sign (-).
ExpandImageUrl 可展开节点的指示符所显示图像的 URL。The URL to an image displayed for the expandable node indicator. 此图像通常为加号 (+)。This image is usually a plus sign (+).
LineImagesFolder 包含用于将父节点连接到子节点的线条图像的文件夹的 URL。The URL to the folder containing the line images used to connect parent nodes to child nodes. 还必须将true属性设置为, 此属性才会生效。 ShowLinesThe ShowLines property must also be set to true for this property to have an effect.
NoExpandImageUrl 为不可展开节点指示符显示的图像的 URL。The URL to an image displayed for the non-expandable node indicator.

备注

不需要自定义每个图像属性。You do not need to customize every image property. 如果未显式设置 image 属性, 则使用内置的默认映像。If an image property is not explicitly set, the built-in default image is used.

TreeView控件还允许您在节点旁边显示复选框。The TreeView control also allows you to display a check box next to a node. 如果将TreeNodeTypes.None属性设置为以外的值, 则复选框将显示在指定节点类型的旁边。 ShowCheckBoxesWhen the ShowCheckBoxes property is set to a value other than TreeNodeTypes.None, check boxes are displayed next to the specified node types.

备注

属性可以设置为TreeNodeTypes枚举成员值的按位组合。 ShowCheckBoxesThe ShowCheckBoxes property can be set to a bitwise combination of the TreeNodeTypes enumeration member values.

每次将页面发送到服务器时, CheckedNodes将自动填充所选节点的集合。Each time the page is posted to the server, the CheckedNodes collection is automatically populated with the selected nodes. 显示复选框时, 可以使用TreeNodeCheckChanged事件来运行自定义例程, 只要复选框的状态在向服务器的各次发送之间发生更改。When check boxes are displayed, you can use the TreeNodeCheckChanged event to run a custom routine whenever the state of a check box changes between posts to the server.

事件Events

TreeView控件提供了几个可对其进行编程的事件。The TreeView control provides several events that you can program against. 这使您可以在每次发生事件时运行自定义例程。This allows you to run a custom routine whenever an event occurs. 下表列出了TreeView控件支持的事件。The following table lists the events that are supported by the TreeView control.

事件Event 说明Description
TreeNodeCheckChanged TreeView控件的复选框在向服务器的各次发送过程间更改状态时发生。Occurs when the check boxes of the TreeView control change state between posts to the server.
SelectedNodeChanged TreeView 控件中选定某个节点时发生。Occurs when a node is selected in the TreeView control.
TreeNodeExpanded TreeView 控件中展开某个节点时发生。Occurs when a node is expanded in the TreeView control.
TreeNodeCollapsed TreeView 控件中折叠某个节点时发生。Occurs when a node is collapsed in the TreeView control.
TreeNodePopulate 当其 PopulateOnDemand 属性设置为 true 的节点在 TreeView 控件中展开时发生。Occurs when a node with its PopulateOnDemand property set to true is expanded in the TreeView control.
TreeNodeDataBound 将数据项绑定到 TreeView 控件中的某个节点时发生。Occurs when a data item is bound to a node in the TreeView control.

滚动Scrolling

TreeView控件没有内置滚动。The TreeView control does not have built-in scrolling. 若要添加滚动, 请TreeView将控件放置Panel在控件中Panel , 并向控件添加滚动条。To add scrolling, place the TreeView control in a Panel control and add scrollbars to the Panel control. 有关详细信息, 请参阅面板 Web 服务器控件概述For more information, see Panel Web Server Control Overview.

可访问性Accessibility

默认情况下, 为此控件呈现的标记可能不符合辅助功能标准。The markup rendered by default for this control might not conform to accessibility standards. 有关此控件的辅助功能支持的详细信息, 请参阅ASP.NET 控件和辅助功能For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

声明性语法Declarative Syntax

<asp:TreeView  
    AccessKey="string"  
    AutoGenerateDataBindings="True|False"  
    BackColor="color name|#dddddd"  
    BorderColor="color name|#dddddd"  
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|  
        Inset|Outset"  
    BorderWidth="size"  
    CollapseImageToolTip="string"  
    CollapseImageUrl="uri"  
    CssClass="string"  
    DataSource="string"  
    DataSourceID="string"  
    EnableClientScript="True|False"  
    Enabled="True|False"  
    EnableTheming="True|False"  
    EnableViewState="True|False"  
    ExpandDepth="string|FullyExpand|0|1|2|3|4|5|6|7|8|9|10|11|12|13|  
        14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30"  
    ExpandImageToolTip="string"  
    ExpandImageUrl="uri"  
    Font-Bold="True|False"  
    Font-Italic="True|False"  
    Font-Names="string"  
    Font-Overline="True|False"  
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|  
       Large|X-Large|XX-Large"  
    Font-Strikeout="True|False"  
    Font-Underline="True|False"  
    ForeColor="color name|#dddddd"  
    Height="size"  
    ID="string"  
    ImageSet="Custom|XPFileExplorer|Msdn|WindowsHelp|Simple|Simple2|  
        BulletedList|BulletedList2|BulletedList3|BulletedList4|  
        Arrows|News|Contacts|Inbox|Events|Faq"  
    LineImagesFolder="string"  
    MaxDataBindDepth="integer"  
    NodeIndent="integer"  
    NodeWrap="True|False"  
    NoExpandImageUrl="uri"  
    OnDataBinding="DataBinding event handler"  
    OnDataBound="DataBound event handler"  
    OnDisposed="Disposed event handler"  
    OnInit="Init event handler"  
    OnLoad="Load event handler"  
    OnPreRender="PreRender event handler"  
    OnSelectedNodeChanged="SelectedNodeChanged event handler"  
    OnTreeNodeCheckChanged="TreeNodeCheckChanged event handler"  
    OnTreeNodeCollapsed="TreeNodeCollapsed event handler"  
    OnTreeNodeDataBound="TreeNodeDataBound event handler"  
    OnTreeNodeExpanded="TreeNodeExpanded event handler"  
    OnTreeNodePopulate="TreeNodePopulate event handler"  
    OnUnload="Unload event handler"  
    PathSeparator="string"  
    PopulateNodesFromClient="True|False"  
    runat="server"  
    ShowCheckBoxes="None|Root|Parent|Leaf|All"  
    ShowExpandCollapse="True|False"  
    ShowLines="True|False"  
    SkinID="string"  
    SkipLinkText="string"  
    Style="string"  
    TabIndex="integer"  
    Target="string"  
    ToolTip="string"  
    Visible="True|False"  
    Width="size"  
>  
        <DataBindings>  
                <asp:TreeNodeBinding  
                    DataMember="string"  
                    Depth="integer"  
                    FormatString="string"  
                    ImageToolTip="string"  
                    ImageToolTipField="string"  
                    ImageUrl="uri"  
                    ImageUrlField="string"  
                    NavigateUrl="uri"  
                    NavigateUrlField="string"  
                    PopulateOnDemand="True|False"  
                    SelectAction="Select|Expand|SelectExpand|None"  
                    ShowCheckBox="string"  
                    Target="string"  
                    TargetField="string"  
                    Text="string"  
                    TextField="string"  
                    ToolTip="string"  
                    ToolTipField="string"  
                    Value="string"  
                    ValueField="string"  
                />  
        </DataBindings>  
        <HoverNodeStyle />  
        <LeafNodeStyle  
            BackColor="color name|#dddddd"  
            BorderColor="color name|#dddddd"  
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|  
                Groove|Ridge|Inset|Outset"  
            BorderWidth="size"  
            ChildNodesPadding="size"  
            CssClass="string"  
            Font-Bold="True|False"  
            Font-Italic="True|False"  
            Font-Names="string"  
            Font-Overline="True|False"  
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|  
                Medium|Large|X-Large|XX-Large"  
            Font-Strikeout="True|False"  
            Font-Underline="True|False"  
            ForeColor="color name|#dddddd"  
            Height="size"  
            HorizontalPadding="size"  
            ImageUrl="uri"  
            NodeSpacing="size"  
            OnDisposed="Disposed event handler"  
            VerticalPadding="size"  
            Width="size"  
        />  
        <LevelStyles>  
                <asp:TreeNodeStyle  
                    BackColor="color name|#dddddd"  
                    BorderColor="color name|#dddddd"  
                    BorderStyle="NotSet|None|Dotted|Dashed|Solid|  
                        Double|Groove|Ridge|Inset|Outset"  
                    BorderWidth="size"  
                    ChildNodesPadding="size"  
                    CssClass="string"  
                    Font-Bold="True|False"  
                    Font-Italic="True|False"  
                    Font-Names="string"  
                    Font-Overline="True|False"  
                    Font-Size="string|Smaller|Larger|XX-Small|  
                        X-Small|Small|Medium|Large|X-Large|XX-Large"  
                    Font-Strikeout="True|False"  
                    Font-Underline="True|False"  
                    ForeColor="color name|#dddddd"  
                    Height="size"  
                    HorizontalPadding="size"  
                    ImageUrl="uri"  
                    NodeSpacing="size"  
                    OnDisposed="Disposed event handler"  
                    VerticalPadding="size"  
                    Width="size"  
                />  
        </LevelStyles>  
        <Nodes>  
                <asp:TreeNode  
                    Checked="True|False"  
                    Expanded="string"  
                    ImageToolTip="string"  
                    ImageUrl="uri"  
                    NavigateUrl="uri"  
                    PopulateOnDemand="True|False"  
                    SelectAction="Select|Expand|SelectExpand|None"  
                    Selected="True|False"  
                    ShowCheckBox="string"  
                    Target="string"  
                    Text="string"  
                    ToolTip="string"  
                    Value="string"  
>  
                </asp:TreeNode>  
        </Nodes>  
        <NodeStyle  
            BackColor="color name|#dddddd"  
            BorderColor="color name|#dddddd"  
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|  
                Groove|Ridge|Inset|Outset"  
            BorderWidth="size"  
            ChildNodesPadding="size"  
            CssClass="string"  
            Font-Bold="True|False"  
            Font-Italic="True|False"  
            Font-Names="string"  
            Font-Overline="True|False"  
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|  
                Medium|Large|X-Large|XX-Large"  
            Font-Strikeout="True|False"  
            Font-Underline="True|False"  
            ForeColor="color name|#dddddd"  
            Height="size"  
            HorizontalPadding="size"  
            ImageUrl="uri"  
            NodeSpacing="size"  
            OnDisposed="Disposed event handler"  
            VerticalPadding="size"  
            Width="size"  
        />  
        <ParentNodeStyle  
            BackColor="color name|#dddddd"  
            BorderColor="color name|#dddddd"  
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|  
                Groove|Ridge|Inset|Outset"  
            BorderWidth="size"  
            ChildNodesPadding="size"  
            CssClass="string"  
            Font-Bold="True|False"  
            Font-Italic="True|False"  
            Font-Names="string"  
            Font-Overline="True|False"  
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|  
                Medium|Large|X-Large|XX-Large"  
            Font-Strikeout="True|False"  
            Font-Underline="True|False"  
            ForeColor="color name|#dddddd"  
            Height="size"  
            HorizontalPadding="size"  
            ImageUrl="uri"  
            NodeSpacing="size"  
            OnDisposed="Disposed event handler"  
            VerticalPadding="size"  
            Width="size"  
        />  
        <RootNodeStyle  
            BackColor="color name|#dddddd"  
            BorderColor="color name|#dddddd"  
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|  
                Groove|Ridge|Inset|Outset"  
            BorderWidth="size"  
            ChildNodesPadding="size"  
            CssClass="string"  
            Font-Bold="True|False"  
            Font-Italic="True|False"  
            Font-Names="string"  
            Font-Overline="True|False"  
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|  
                Medium|Large|X-Large|XX-Large"  
            Font-Strikeout="True|False"  
            Font-Underline="True|False"  
            ForeColor="color name|#dddddd"  
            Height="size"  
            HorizontalPadding="size"  
            ImageUrl="uri"  
            NodeSpacing="size"  
            OnDisposed="Disposed event handler"  
            VerticalPadding="size"  
            Width="size"  
        />  
        <SelectedNodeStyle  
            BackColor="color name|#dddddd"  
            BorderColor="color name|#dddddd"  
            BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|  
                Groove|Ridge|Inset|Outset"  
            BorderWidth="size"  
            ChildNodesPadding="size"  
            CssClass="string"  
            Font-Bold="True|False"  
            Font-Italic="True|False"  
            Font-Names="string"  
            Font-Overline="True|False"  
            Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|  
                Medium|Large|X-Large|XX-Large"  
            Font-Strikeout="True|False"  
            Font-Underline="True|False"  
            ForeColor="color name|#dddddd"  
            Height="size"  
            HorizontalPadding="size"  
            ImageUrl="uri"  
            NodeSpacing="size"  
            OnDisposed="Disposed event handler"  
            VerticalPadding="size"  
            Width="size"  
        />  
</asp:TreeView>  

构造函数

TreeView()

初始化 TreeView 类的新实例。Initializes a new instance of the TreeView class.

属性

AccessKey

获取或设置使您得以快速导航到 Web 服务器控件的访问键。Gets or sets the access key that allows you to quickly navigate to the Web server control.

(继承自 WebControl)
Adapter

获取控件的浏览器特定适配器。Gets the browser-specific adapter for the control.

(继承自 Control)
AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。Gets or sets the application-relative virtual directory of the Page or UserControl object that contains this control.

(继承自 Control)
Attributes

获取与控件的特性不对应的任意特性(只用于呈现)的集合。Gets the collection of arbitrary attributes (for rendering only) that do not correspond to properties on the control.

(继承自 WebControl)
AutoGenerateDataBindings

获取或设置一个值,该值指示 TreeView 控件是否自动生成树节点绑定。Gets or sets a value indicating whether the TreeView control automatically generates tree node bindings.

BackColor

获取或设置 Web 服务器控件的背景色。Gets or sets the background color of the Web server control.

(继承自 WebControl)
BindingContainer

获取包含该控件的数据绑定的控件。Gets the control that contains this control's data binding.

(继承自 Control)
BorderColor

获取或设置 Web 控件的边框颜色。Gets or sets the border color of the Web control.

(继承自 WebControl)
BorderStyle

获取或设置 Web 服务器控件的边框样式。Gets or sets the border style of the Web server control.

(继承自 WebControl)
BorderWidth

获取或设置 Web 服务器控件的边框宽度。Gets or sets the border width of the Web server control.

(继承自 WebControl)
CheckedNodes

获取 TreeNode 对象的集合,这些对象表示在 TreeView 控件中显示的选中了复选框的节点。Gets a collection of TreeNode objects that represent the nodes in the TreeView control that display a selected check box.

ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。Gets a value that indicates whether the server control's child controls have been created.

(继承自 Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。Gets the control ID for HTML markup that is generated by ASP.NET.

(继承自 Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。Gets or sets the algorithm that is used to generate the value of the ClientID property.

(继承自 Control)
ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。Gets a character value representing the separator character used in the ClientID property.

(继承自 Control)
CollapseImageToolTip

获取或设置可折叠节点的指示符所显示图像的工具提示。Gets or sets the ToolTip for the image that is displayed for the collapsible node indicator.

CollapseImageUrl

获取或设置自定义图像的 URL,该图像用作可折叠节点的指示符。Gets or sets the URL to a custom image for the collapsible node indicator.

Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。Gets the HttpContext object associated with the server control for the current Web request.

(继承自 Control)
Controls

获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。Gets a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy.

(继承自 Control)
ControlStyle

获取 Web 服务器控件的样式。Gets the style of the Web server control. 此属性主要由控件开发人员使用。This property is used primarily by control developers.

(继承自 WebControl)
ControlStyleCreated

获取一个值,该值指示是否已为 Style 属性创建了 ControlStyle 对象。Gets a value indicating whether a Style object has been created for the ControlStyle property. 此属性主要由控件开发人员使用。This property is primarily used by control developers.

(继承自 WebControl)
CssClass

获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。Gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client.

(继承自 WebControl)
DataBindings

获取 TreeNodeBinding 对象的集合,这些对象定义数据项与其绑定到的节点之间的关系。Gets a collection of TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to.

DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。Gets a reference to the naming container if the naming container implements IDataItemContainer.

(继承自 Control)
DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。Gets a reference to the naming container if the naming container implements IDataKeysControl.

(继承自 Control)
DataSource

获取或设置对象,数据绑定控件从该对象中检索其数据项列表。Gets or sets the object from which the data-bound control retrieves its list of data items.

(继承自 BaseDataBoundControl)
DataSourceID

获取或设置控件的 ID,数据绑定控件从该控件中检索其数据项列表。Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.

(继承自 HierarchicalDataBoundControl)
DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。Gets a value indicating whether a control is being used on a design surface.

(继承自 Control)
EnableClientScript

获取或设置一个值,指示 TreeView 控件是否呈现客户端脚本以处理展开和折叠事件。Gets or sets a value indicating whether the TreeView control renders client-side script to handle expanding and collapsing events.

Enabled

获取或设置一个值,该值指示是否启用 Web 服务器控件。Gets or sets a value indicating whether the Web server control is enabled.

(继承自 WebControl)
EnableTheming

获取或设置一个值,该值指示主题是否应用于该控件。Gets or sets a value indicating whether themes apply to this control.

(继承自 WebControl)
EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.

(继承自 Control)
Events

获取控件的事件处理程序委托列表。Gets a list of event handler delegates for the control. 此属性是只读的。This property is read-only.

(继承自 Control)
ExpandDepth

获取或设置第一次显示 TreeView 控件时所展开的层次数。Gets or sets the number of levels that are expanded when a TreeView control is displayed for the first time.

ExpandImageToolTip

获取或设置可展开节点的指示符所显示图像的工具提示。Gets or sets the ToolTip for the image that is displayed for the expandable node indicator.

ExpandImageUrl

获取或设置自定义图像的 URL,该图像用作可展开节点的指示符。Gets or sets the URL to a custom image for the expandable node indicator.

Font

获取与 Web 服务器控件关联的字体属性。Gets the font properties associated with the Web server control.

(继承自 WebControl)
ForeColor

获取或设置 Web 服务器控件的前景色(通常是文本颜色)。Gets or sets the foreground color (typically the color of the text) of the Web server control.

(继承自 WebControl)
HasAttributes

获取一个值,该值指示控件是否具有特性集。Gets a value indicating whether the control has attributes set.

(继承自 WebControl)
HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。Gets a value indicating whether the current server control's child controls have any saved view-state settings.

(继承自 Control)
Height

获取或设置 Web 服务器控件的高度。Gets or sets the height of the Web server control.

(继承自 WebControl)
HoverNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象可用于设置当鼠标指针停在一个节点上时该节点的外观。Gets a reference to the TreeNodeStyle object that allows you to set the appearance of a node when the mouse pointer is positioned over it.

ID

获取或设置分配给服务器控件的编程标识符。Gets or sets the programmatic identifier assigned to the server control.

(继承自 Control)
IdSeparator

获取用于分隔控件标识符的字符。Gets the character used to separate control identifiers.

(继承自 Control)
ImageSet

获取或设置用于 TreeView 控件的图像组。Gets or sets the group of images to use for the TreeView control.

Initialized

获取一个值,该值指示数据绑定控件是否已经初始化。Gets a value indicating whether the data-bound control has been initialized.

(继承自 BaseDataBoundControl)
IsBoundUsingDataSourceID

获取指示是否设置 DataSourceID 属性的值。Gets a value indicating whether the DataSourceID property is set.

(继承自 BaseDataBoundControl)
IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。Gets a value indicating whether controls contained within this control have control state.

(继承自 Control)
IsDataBindingAutomatic

获取一个值,该值指示数据绑定功能是否是自动的。Gets a value that indicates whether data binding is automatic.

(继承自 BaseDataBoundControl)
IsEnabled

获取一个值,该值指示是否启用控件。Gets a value indicating whether the control is enabled.

(继承自 WebControl)
IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。Gets a value that indicates whether the server control is saving changes to its view state.

(继承自 Control)
IsUsingModelBinders

在派生类中实现时,获取一个值,该值指示控件是否使用模型联编程序。When implemented in a derived class, gets a value that indicates whether the control is using model binders.

(继承自 BaseDataBoundControl)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。Gets a value indicating whether view state is enabled for this control.

(继承自 Control)
LeafNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象可用于设置叶节点的外观。Gets a reference to the TreeNodeStyle object that allows you to set the appearance of leaf nodes.

LevelStyles

获取 Style 对象的集合,这些对象表示树中各个级别上的节点样式。Gets a collection of Style objects that represent the node styles at the individual levels of the tree.

LineImagesFolder

获取或设置文件夹的路径,该文件夹包含用于连接子节点和父节点的线条图像。Gets or sets the path to a folder that contains the line images that are used to connect child nodes to parent nodes.

LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。Gets a value indicating whether the control participates in loading its view state by ID instead of index.

(继承自 Control)
MaxDataBindDepth

获取或设置要绑定到 TreeView 控件的最大树级别数。Gets or sets the maximum number of tree levels to bind to the TreeView control.

NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。Gets a reference to the server control's naming container, which creates a unique namespace for differentiating between server controls with the same ID property value.

(继承自 Control)
NodeIndent

获取或设置 TreeView 控件的子节点的缩进量(以像素为单位)。Gets or sets the indentation amount (in pixels) for the child nodes of the TreeView control.

Nodes

获取 TreeNode 对象的集合,它表示 TreeView 控件中根节点。Gets a collection of TreeNode objects that represents the root nodes in the TreeView control.

NodeStyle

获取对 TreeNodeStyle 对象的引用,该对象用于设置 TreeView 控件中节点的默认外观。Gets a reference to the TreeNodeStyle object that allows you to set the default appearance of the nodes in the TreeView control.

NodeWrap

获取或设置一个值,它指示空间不足时节点中的文本是否换行。Gets or sets a value indicating whether text wraps in a node when the node runs out of space.

NoExpandImageUrl

获取或设置自定义图像的 URL,该图像用作不可展开节点的指示符。Gets or sets the URL to a custom image for the non-expandable node indicator.

Page

获取对包含服务器控件的 Page 实例的引用。Gets a reference to the Page instance that contains the server control.

(继承自 Control)
Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。Gets a reference to the server control's parent control in the page control hierarchy.

(继承自 Control)
ParentNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象用于设置 TreeView 控件中父节点的外观。Gets a reference to the TreeNodeStyle object that allows you to set the appearance of parent nodes in the TreeView control.

PathSeparator

获取或设置用于分隔由 ValuePath 属性指定的节点值的字符。Gets or sets the character that is used to delimit the node values that are specified by the ValuePath property.

PopulateNodesFromClient

获取或设置一个值,它指示是否按需从客户端填充节点数据。Gets or sets a value indicating whether node data is populated on demand from the client.

RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.

(继承自 Control)
RequiresDataBinding

获取或设置一个值,该值指示是否应调用 DataBind() 方法。Gets or sets a value indicating whether the DataBind() method should be called.

(继承自 BaseDataBoundControl)
RootNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象用于设置 TreeView 控件中根节点的外观。Gets a reference to the TreeNodeStyle object that allows you to set the appearance of the root node in the TreeView control.

SelectedNode

获取表示 TreeNode 控件中选定节点的 TreeView 对象。Gets a TreeNode object that represents the selected node in the TreeView control.

SelectedNodeStyle

获取 TreeNodeStyle 对象,该对象控制 TreeView 控件中选定节点的外观。Gets the TreeNodeStyle object that controls the appearance of the selected node in the TreeView control.

SelectedValue

获取选定节点的值。Gets the value of the selected node.

ShowCheckBoxes

获取或设置一个值,它指示哪些节点类型将在 TreeView 控件中显示复选框。Gets or sets a value indicating which node types will display a check box in the TreeView control.

ShowExpandCollapse

获取或设置一个值,它指示是否显示展开节点指示符。Gets or sets a value indicating whether expansion node indicators are displayed.

ShowLines

获取或设置一个值,它指示是否显示连接子节点和父节点的线条。Gets or sets a value indicating whether lines connecting child nodes to parent nodes are displayed.

Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。Gets information about the container that hosts the current control when rendered on a design surface.

(继承自 Control)
SkinID

获取或设置要应用于控件的外观。Gets or sets the skin to apply to the control.

(继承自 WebControl)
SkipLinkText

获取或设置一个值,它用于为屏幕读取器呈现替换文字以跳过该控件的内容。Gets or sets a value that is used to render alternate text for screen readers to skip the content for the control.

Style

获取将在 Web 服务器控件的外部标记上呈现为样式特性的文本特性的集合。Gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control.

(继承自 WebControl)
SupportsDisabledAttribute

获取一个值,该值指示在控件的 IsEnabled 属性为 disabled 时,控件是否应将呈现的 HTML 元素的 false 特性设置为“disabled”。Gets a value that indicates whether the control should set the disabled attribute of the rendered HTML element to "disabled" when the control's IsEnabled property is false.

(继承自 BaseDataBoundControl)
TabIndex

获取或设置 Web 服务器控件的选项卡索引。Gets or sets the tab index of the Web server control.

(继承自 WebControl)
TagKey

获取 HtmlTextWriterTag 控件的 TreeView 值。Gets the HtmlTextWriterTag value for the TreeView control.

TagName

获取控件标记的名称。Gets the name of the control tag. 此属性主要由控件开发人员使用。This property is used primarily by control developers.

(继承自 WebControl)
Target

获取或设置要在其中显示与节点相关联的网页内容的目标窗口或框架。Gets or sets the target window or frame in which to display the Web page content that is associated with a node.

TemplateControl

获取或设置对包含该控件的模板的引用。Gets or sets a reference to the template that contains this control.

(继承自 Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。Gets the virtual directory of the Page or UserControl that contains the current server control.

(继承自 Control)
ToolTip

获取或设置当鼠标指针悬停在 Web 服务器控件上时显示的文本。Gets or sets the text displayed when the mouse pointer hovers over the Web server control.

(继承自 WebControl)
UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。Gets the unique, hierarchically qualified identifier for the server control.

(继承自 Control)
ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。Gets or sets a value that indicates whether the control checks client input from the browser for potentially dangerous values.

(继承自 Control)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。Gets a dictionary of state information that allows you to save and restore the view state of a server control across multiple requests for the same page.

(继承自 Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。Gets a value that indicates whether the StateBag object is case-insensitive.

(继承自 Control)
ViewStateMode

获取或设置此控件的视图状态模式。Gets or sets the view-state mode of this control.

(继承自 Control)
Visible

获取或设置一个值,该值指示控件是否作为 UI 呈现在页上。Gets or sets a value indicating whether the control is rendered as UI on the page.

Width

获取或设置 Web 服务器控件的宽度。Gets or sets the width of the Web server control.

(继承自 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

将需要呈现的 HTML 特性和样式添加到指定的 HtmlTextWriter 控件中。Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter control.

AddedControl(Control, Int32)

在子控件添加到 Control 对象的 Controls 集合后调用。Called after a child control is added to the Controls collection of the Control object.

(继承自 Control)
AddParsedSubObject(Object)

通知服务器控件,分析了一个元素(XML 或 HTML),并将该元素添加到服务器控件的 ControlCollection 对象中。Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object.

(继承自 Control)
ApplyStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,覆盖控件的所有现有的样式元素。Copies any nonblank elements of the specified style to the Web control, overwriting any existing style elements of the control. 此方法主要由控件开发人员使用。This method is primarily used by control developers.

(继承自 WebControl)
ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。Applies the style properties defined in the page style sheet to the control.

(继承自 Control)
BeginRenderTracing(TextWriter, Object)

开始输出数据的设计时追踪。Begins design-time tracing of rendering data.

(继承自 Control)
BuildProfileTree(String, Boolean)

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page.

(继承自 Control)
ClearCachedClientID()

将缓存的 ClientID 值设置为 nullSets the cached ClientID value to null.

(继承自 Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。Deletes the control-state information for the server control's child controls.

(继承自 Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。Deletes the view-state and control-state information for all the server control's child controls.

(继承自 Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。Deletes the view-state information for all the server control's child controls.

(继承自 Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 InheritSets the ClientIDMode property of the current control instance and of any child controls to Inherit.

(继承自 Control)
CollapseAll()

关闭树中的每个节点。Closes every node in the tree.

ConfirmInitState()

设置数据绑定控件的初始化状态。Sets the initialized state of the data-bound control.

(继承自 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

Style 对象未封装的属性从指定的 Web 服务器控件复制到从中调用此方法的 Web 服务器控件。Copies the properties not encapsulated by the Style object from the specified Web server control to the Web server control that this method is called from. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
CreateChildControls()

由 ASP.NET 页框架调用,以通知服务器控件在准备回发或呈现时使用基于撰写的实现来创建其所包含任何子控件。Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.

(继承自 Control)
CreateControlCollection()

创建用于存储子控件的集合。Creates a collection to store child controls.

CreateControlStyle()

创建由 WebControl 类在内部用来实现所有与样式有关的属性的样式对象。Creates the style object that is used internally by the WebControl class to implement all style related properties. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
CreateNode()

返回 TreeNode 类的新实例。Returns a new instance of the TreeNode class. CreateNode() 是一个帮助器方法。The CreateNode() is a helper method.

DataBind()

调用基类的 DataBind() 方法。Calls the DataBind() method of the base class.

DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event.

(继承自 Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。Binds a data source to the server control's child controls.

(继承自 Control)
Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。Enables a server control to perform final clean up before it is released from memory.

(继承自 Control)
EndRenderTracing(TextWriter, Object)

结束输出数据的设计时追踪。Ends design-time tracing of rendering data.

(继承自 Control)
EnsureChildControls()

确定服务器控件是否包含子控件。Determines whether the server control contains child controls. 如果不包含,则创建子控件。If it does not, it creates child controls.

(继承自 Control)
EnsureDataBound()

如果设置了 DataBind() 属性且数据绑定控件标记为需要绑定,则调用 DataSourceID 方法。Calls the DataBind() method if the DataSourceID property is set and the data-bound control is marked to require binding.

(继承自 BaseDataBoundControl)
EnsureID()

为尚未分配标识符的控件创建标识符。Creates an identifier for controls that do not have an identifier assigned.

(继承自 Control)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
ExpandAll()

打开树中的每个节点。Opens every node in the tree.

FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。Searches the current naming container for a server control with the specified id parameter.

(继承自 Control)
FindControl(String, Int32)

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. 不应重写此版本的 FindControl 方法。You should not override this version of the FindControl method.

(继承自 Control)
FindNode(String)

检索 TreeNode 控件中指定值路径处的 TreeView 对象。Retrieves the TreeNode object in the TreeView control at the specified value path.

Focus()

为控件设置输入焦点。Sets input focus to a control.

(继承自 Control)
GetCallbackResult()

返回以控件为目标的回调事件的结果。Returns the result of a callback event that targets a control.

GetData(String)

检索数据绑定控件用于执行数据操作的 HierarchicalDataSourceView 对象。Retrieves a HierarchicalDataSourceView object that the data-bound control uses to perform data operations.

(继承自 HierarchicalDataBoundControl)
GetDataSource()

如果存在与数据绑定控件关联的 IHierarchicalDataSource,则检索它。Retrieves the IHierarchicalDataSource that the data-bound control is associated with, if any.

(继承自 HierarchicalDataBoundControl)
GetDesignModeState()

获取控件的设计时数据。Gets design-time data for a control.

(继承自 Control)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetRouteUrl(Object)

获取与一组路由参数对应的 URL。Gets the URL that corresponds to a set of route parameters.

(继承自 Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。Gets the URL that corresponds to a set of route parameters.

(继承自 Control)
GetRouteUrl(String, Object)

获取与一组路由参数以及某个路由名称对应的 URL。Gets the URL that corresponds to a set of route parameters and a route name.

(继承自 Control)
GetRouteUrl(String, RouteValueDictionary)

获取与一组路由参数以及某个路由名称对应的 URL。Gets the URL that corresponds to a set of route parameters and a route name.

(继承自 Control)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。Returns the prefixed portion of the UniqueID property of the specified control.

(继承自 Control)
HasControls()

确定服务器控件是否包含任何子控件。Determines if the server control contains any child controls.

(继承自 Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。Returns a value indicating whether events are registered for the control or any child controls.

(继承自 Control)
IsLiteralContent()

确定服务器控件是否只包含文字内容。Determines if the server control holds only literal content.

(继承自 Control)
LoadControlState(Object)

SaveControlState() 方法保存的上一个页请求还原控件状态信息。Restores control-state information from a previous page request that was saved by the SaveControlState() method.

(继承自 Control)
LoadPostData(String, NameValueCollection)

处理 TreeView 控件的回发数据。Processes postback data for the TreeView control.

LoadViewState(Object)

加载以前保存的 TreeView 控件的视图状态。Loads the previously saved view state of the TreeView control.

MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。Retrieves the physical path that a virtual path, either absolute or relative, maps to.

(继承自 Control)
MarkAsDataBound()

将视图状态中的控件状态设置为成功绑定到数据。Sets the state of the control in view state as successfully bound to data.

(继承自 HierarchicalDataBoundControl)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MergeStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,但不覆盖该控件现有的任何样式元素。Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. 此方法主要由控件开发人员使用。This method is used primarily by control developers.

(继承自 WebControl)
OnBubbleEvent(Object, EventArgs)

确定服务器控件的事件是否沿页的 UI 服务器控件层次结构向上传递。Determines whether the event for the server control is passed up the page's UI server control hierarchy.

(继承自 Control)
OnDataBinding(EventArgs)

引发 DataBinding 事件。Raises the DataBinding event.

(继承自 Control)
OnDataBound(EventArgs)

引发 DataBound 事件。Raises the DataBound event.

(继承自 BaseDataBoundControl)
OnDataPropertyChanged()

在其中一个基数据源标识属性更改时被调用,以将数据绑定控件重新绑定到其数据。Called when one of the base data source identification properties is changed, to re-bind the data-bound control to its data.

(继承自 HierarchicalDataBoundControl)
OnDataSourceChanged(Object, EventArgs)

在与数据绑定控件一起使用的 IHierarchicalDataSource 实例引发 DataSourceChanged 事件时被调用。Called when the IHierarchicalDataSource instance that the data-bound control works with raises the DataSourceChanged event.

(继承自 HierarchicalDataBoundControl)
OnInit(EventArgs)

引发 Init 事件。Raises the Init event.

OnLoad(EventArgs)

处理 Load 事件。Handles the Load event.

(继承自 HierarchicalDataBoundControl)
OnPagePreLoad(Object, EventArgs)

在加载数据绑定控件之前设置该控件的初始化状态。Sets the initialized state of the data-bound control before the control is loaded.

(继承自 HierarchicalDataBoundControl)
OnPreRender(EventArgs)

引发 PreRender 事件。Raises the PreRender event.

OnSelectedNodeChanged(EventArgs)

引发 TreeView 控件的 SelectedNodeChanged 事件。Raises the SelectedNodeChanged event of the TreeView control.

OnTreeNodeCheckChanged(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeCheckChanged 事件。Raises the TreeNodeCheckChanged event of the TreeView control.

OnTreeNodeCollapsed(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeCollapsed 事件。Raises the TreeNodeCollapsed event of the TreeView control.

OnTreeNodeDataBound(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeDataBound 事件。Raises the TreeNodeDataBound event of the TreeView control.

OnTreeNodeExpanded(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeExpanded 事件。Raises the TreeNodeExpanded event of the TreeView control.

OnTreeNodePopulate(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodePopulate 事件。Raises the TreeNodePopulate event of the TreeView control.

OnUnload(EventArgs)

引发 Unload 事件。Raises the Unload event.

(继承自 Control)
OpenFile(String)

获取用于读取文件的 StreamGets a Stream used to read a file.

(继承自 Control)
PerformDataBinding()

基于数据源创建所有节点。Creates all the nodes based on the data source.

PerformSelect()

从关联的数据源中检索数据。Retrieves data from the associated data source.

(继承自 HierarchicalDataBoundControl)
RaiseBubbleEvent(Object, EventArgs)

将所有事件源及其信息分配给控件的父级。Assigns any sources of the event and its information to the control's parent.

(继承自 Control)
RaiseCallbackEvent(String)

使用指定参数引发回调事件。Raises the callback event using the specified arguments.

RaisePostBackEvent(String)

启用 TreeView 控件以处理将窗体发送到服务器时引发的事件。Enables the TreeView control to process an event that is raised when a form is posted to the server. RaisePostBackEvent(String) 方法是 ICallbackEventHandler.RaiseCallbackEvent(String) 方法的帮助器方法。The RaisePostBackEvent(String) method is a helper method for the ICallbackEventHandler.RaiseCallbackEvent(String) method.

RaisePostDataChangedEvent()

TreeView 控件发出信号,以通知 ASP.NET 应用程序该控件的状态已更改。Signals the TreeView control to notify the ASP.NET application that the state of the control has changed.

RemovedControl(Control)

Control 对象的 Controls 集合移除子控件后调用。Called after a child control is removed from the Controls collection of the Control object.

(继承自 Control)
Render(HtmlTextWriter)

将控件呈现给指定的 HTML 编写器。Renders the control to the specified HTML writer.

(继承自 WebControl)
RenderBeginTag(HtmlTextWriter)

将控件的 HTML 开始标记呈现到指定的编写器中。Renders the HTML opening tag of the control to the specified writer.

RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,此对象编写将在客户端呈现的内容。Outputs the content of a server control's children to a provided HtmlTextWriter object, which writes the content to be rendered on the client.

(继承自 Control)
RenderContents(HtmlTextWriter)

呈现 TreeView 控件中的节点。Renders the nodes in the TreeView control.

RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

(继承自 Control)
RenderControl(HtmlTextWriter, ControlAdapter)

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

(继承自 Control)
RenderEndTag(HtmlTextWriter)

将控件的 HTML 结束标记呈现到指定的编写器中。Renders the HTML closing tag of the control to the specified writer.

ResolveAdapter()

获取负责呈现指定控件的控件适配器。Gets the control adapter responsible for rendering the specified control.

(继承自 Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。Gets a URL that can be used by the browser.

(继承自 Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。Converts a URL into one that is usable on the requesting client.

(继承自 Control)
SaveControlState()

保存将页面回发到服务器之后发生的所有服务器控件状态更改。Saves any server control state changes that have occurred since the time the page was posted back to the server.

(继承自 Control)
SaveViewState()

保存 TreeView 控件的状态。Saves the state of the TreeView control.

SetDesignModeState(IDictionary)

为控件设置设计时数据。Sets design-time data for a control.

(继承自 Control)
SetNodeDataBound(TreeNode, Boolean)

允许派生类设置指定的 TreeNode 控件是否被数据绑定。Allows a derived class to set whether the specified TreeNode control is data-bound.

SetNodeDataItem(TreeNode, Object)

允许派生类为指定的 TreeNode 控件设置数据项。Allows a derived class to set the data item for the specified TreeNode control.

SetNodeDataPath(TreeNode, String)

允许派生类为指定的 TreeNode 控件设置数据路径。Allows a derived class to set the data path for the specified TreeNode control.

SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。Assigns an event handler delegate to render the server control and its content into its parent control.

(继承自 Control)
SetTraceData(Object, Object)

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。Sets trace data for design-time tracing of rendering data, using the trace data key and the trace data value.

(继承自 Control)
SetTraceData(Object, Object, Object)

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。Sets trace data for design-time tracing of rendering data, using the traced object, the trace data key, and the trace data value.

(继承自 Control)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
TrackViewState()

跟踪 TreeView 控件的视图状态更改,以便可将它们存储在该控件的 StateBag 对象中。Tracks view-state changes to the TreeView control so that they can be stored in the StateBag object for the control. 通过 StateBag 属性可以访问此 ViewStateThis StateBag is accessible through the ViewState property.

ValidateDataSource(Object)

验证数据绑定控件绑定到的对象是否可以和该控件一同使用。Verifies that the object a data-bound control binds to is one it can work with.

(继承自 HierarchicalDataBoundControl)

事件

DataBinding

当服务器控件绑定到数据源时发生。Occurs when the server control binds to a data source.

(继承自 Control)
DataBound

在服务器控件绑定到数据源后发生。Occurs after the server control binds to a data source.

(继承自 BaseDataBoundControl)
Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。Occurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested.

(继承自 Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。Occurs when the server control is initialized, which is the first step in its lifecycle.

(继承自 Control)
Load

当服务器控件加载到 Page 对象中时发生。Occurs when the server control is loaded into the Page object.

(继承自 Control)
PreRender

在加载 Control 对象之后、呈现之前发生。Occurs after the Control object is loaded but prior to rendering.

(继承自 Control)
SelectedNodeChanged

TreeView 控件中选定某个节点时发生。Occurs when a node is selected in the TreeView control.

TreeNodeCheckChanged

TreeView 控件中的复选框在向服务器的两次发送过程之间状态有所更改时发生。Occurs when a check box in the TreeView control changes state between posts to the server.

TreeNodeCollapsed

TreeView 控件中折叠某个节点时发生。Occurs when a node is collapsed in the TreeView control.

TreeNodeDataBound

将数据项绑定到 TreeView 控件中的某个节点时发生。Occurs when a data item is bound to a node in the TreeView control.

TreeNodeExpanded

TreeView 控件中展开某个节点时发生。Occurs when a node is expanded in the TreeView control.

TreeNodePopulate

当其 PopulateOnDemand 属性设置为 true 的节点在 TreeView 控件中展开时发生。Occurs when a node with its PopulateOnDemand property set to true is expanded in the TreeView control.

Unload

当服务器控件从内存中卸载时发生。Occurs when the server control is unloaded from memory.

(继承自 Control)

显式接口实现

IAttributeAccessor.GetAttribute(String)

获取具有指定名称的 Web 控件的特性。Gets an attribute of the Web control with the specified name.

(继承自 WebControl)
IAttributeAccessor.SetAttribute(String, String)

将 Web 控件的特性设置为指定的名称和值。Sets an attribute of the Web control to the specified name and value.

(继承自 WebControl)
ICallbackEventHandler.GetCallbackResult()

返回以控件为目标的回调事件的结果。Returns the result of a callback event that targets a control.

ICallbackEventHandler.RaiseCallbackEvent(String)

使用指定参数引发回调事件。Raises the callback event using the specified arguments.

IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参见 ControlBuilderFor a description of this member, see ControlBuilder.

(继承自 Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参见 GetDesignModeState()For a description of this member, see GetDesignModeState().

(继承自 Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

有关此成员的说明,请参见 SetDesignModeState(IDictionary)For a description of this member, see SetDesignModeState(IDictionary).

(继承自 Control)
IControlDesignerAccessor.SetOwnerControl(Control)

有关此成员的说明,请参见 SetOwnerControl(Control)For a description of this member, see SetOwnerControl(Control).

(继承自 Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参见 UserDataFor a description of this member, see UserData.

(继承自 Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参见 DataBindingsFor a description of this member, see DataBindings.

(继承自 Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参见 HasDataBindingsFor a description of this member, see HasDataBindings.

(继承自 Control)
IExpressionsAccessor.Expressions

有关此成员的说明,请参见 ExpressionsFor a description of this member, see Expressions.

(继承自 Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参见 HasExpressionsFor a description of this member, see HasExpressions.

(继承自 Control)
IParserAccessor.AddParsedSubObject(Object)

有关此成员的说明,请参见 AddParsedSubObject(Object)For a description of this member, see AddParsedSubObject(Object).

(继承自 Control)
IPostBackDataHandler.LoadPostData(String, NameValueCollection)

处理 TreeView 控件的回发数据。Processes postback data for the TreeView control.

IPostBackDataHandler.RaisePostDataChangedEvent()

TreeView 控件发出信号,以通知 ASP.NET 应用程序该控件的状态已更改。Signals the TreeView control to notify the ASP.NET application that the state of the control has changed.

IPostBackEventHandler.RaisePostBackEvent(String)

启用 TreeView 控件以处理将窗体发送到服务器时引发的事件。Enables the TreeView control to process an event that is raised when a form is posted to the server.

扩展方法

EnablePersistedSelection(BaseDataBoundControl)

使选定内容能够保留在支持选择和分页的数据控件中。Enables selection to be persisted in data controls that support selection and paging.

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。Returns the data source that is associated with the data control for the specified control.

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。Returns the field template for the specified column in the specified control's naming container.

FindMetaTable(Control)

返回包含数据控件的元表对象。Returns the metatable object for the containing data control.

适用于

另请参阅