TreeView 类

定义

在树结构中显示分层数据,例如目录。

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
[<System.Web.UI.ControlValueProperty("SelectedValue")>]
type TreeView = class
    inherit HierarchicalDataBoundControl
    interface IPostBackEventHandler
    interface IPostBackDataHandler
    interface ICallbackEventHandler
Public Class TreeView
Inherits HierarchicalDataBoundControl
Implements ICallbackEventHandler, IPostBackDataHandler, IPostBackEventHandler
继承
属性
实现

示例

本部分包含七个代码示例:

  • 第一个代码示例演示如何为第二个代码示例设置帧。

  • 第二个代码示例演示如何使用声明性语法在 控件中 TreeView 显示静态数据。

  • 第三个代码示例演示如何将 TreeView 控件绑定到 XML 数据源。

  • 第四个代码示例提供第三个代码示例的示例 XML 数据。

  • 第五个SiteMapDataSource代码示例演示如何通过将 控件绑定到 控件来使用该TreeView控件进行网站导航。

  • 第六个代码示例提供第五个代码示例的示例站点地图数据。

  • 第七个代码示例演示如何从客户端填充 控件中的 TreeView 节点。

下面的代码示例演示如何为以下代码示例设置帧。


<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 显示静态数据。 此示例在上述示例的框架集中用于显示目录。


<%@ 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 数据源。 若要使此示例正常工作,必须将此示例后提供的示例 XML 数据复制到名为 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 数据。

<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>

下面的代码示例演示如何通过将 控件绑定到 SiteMapDataSource 控件来使用该TreeView控件进行网站导航。 若要使此示例正常工作,必须将此示例后提供的示例站点地图数据复制到名为 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>

下面的代码示例提供了上述代码示例的示例站点地图数据。

<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 节点。 启用客户端节点填充后,节点将在客户端上动态填充,而无需发回服务器。


<%@ 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>

注解

本主题内容:

介绍

控件 TreeView 用于在树结构中显示分层数据(如目录或文件目录),并支持以下功能:

  • 允许控件的节点绑定到 XML、表格或关系数据的数据绑定。

  • 通过与 控件的集成进行 SiteMapDataSource 网站导航。

  • 可显示为纯文本或超链接的节点文本。

  • TreeView 编程方式访问对象模型,以动态方式创建树、填充节点、设置属性等。

  • ) 支持的浏览器上的客户端节点填充 (。

  • 在每个节点旁边显示检查框的功能。

  • 可通过主题、用户定义的图像和样式自定义外观。

    注意

    仅当 设置为 trueEnableClientScript, 控件TreeView才设计为在 控件内UpdatePanel使用。 UpdatePanel 控件用于更新页面的选定区域,而不是使用回发更新整个页面。 有关详细信息,请参阅 UpdatePanel 控件概述分页呈现概述

Nodes

控件 TreeView 由节点组成。 树中的每个条目称为节点,由 TreeNode 对象表示。 节点类型定义如下:

  • 包含其他节点的节点称为 父节点

  • 另一个节点包含的节点称为 子节点

  • 没有子级的节点称为 叶节点

  • 未包含在任何其他节点中但是所有其他节点的上级节点的节点是 根节点

节点可以是父节点和子节点,但根节点、父节点和叶节点是互斥的。 节点的多个视觉和行为属性取决于节点是根节点、子节点还是叶节点。

尽管典型的树结构只有一个根节点,但 TreeView 控件允许向树结构添加多个根节点。 如果要显示项列表而不显示单个根节点,这非常有用,如产品类别列表所示。

每个节点都有一个 Text 属性和一个 Value 属性。 属性的值 Text 显示在 中 TreeView,而 Value 属性用于存储有关节点的任何其他数据,例如传递给与节点关联的回发事件的数据。

节点可以处于以下两种模式之一:选择模式和导航模式。 默认情况下,节点处于选择模式。 若要将节点置于导航模式,请将节点的 属性设置为 NavigateUrl 空字符串 (“”) 以外的值。 若要将节点置于选择模式,请将节点的 属性设置为 NavigateUrl 空字符串 (“”) 。

注意

某些 Internet 浏览器存在可能影响控件性能 TreeView 的限制。 例如,Microsoft Internet Explorer 6.0 发布的 URL 字符限制为 2067 个字符。 如果节点的 URL 中的字符数大于该数目,则扩展该节点将失败,并且不会引发异常。

静态数据

控件的最简单数据模型 TreeView 是静态数据。 若要使用声明性语法显示静态数据,请先在控件的开始标记和结束 <Nodes> 标记之间嵌套开始标记和结束标记 TreeView 。 接下来,通过在开始标记和结束<Nodes>标记之间嵌套<asp:TreeNode>元素来创建树结构。 每个 <asp:TreeNode> 元素表示树中的一个节点并映射到 对象 TreeNode 。 可以通过设置其 <asp:TreeNode> 元素的属性来设置每个节点的属性。 若要创建子节点,请在父节点的开始标记和结束<asp:TreeNode>标记之间嵌套其他<asp:TreeNode>元素。

绑定到数据

控件 TreeView 也可以绑定到数据。 可以使用两种方法之一将 TreeView 控件绑定到适当的数据源类型:

绑定到数据源时,其中每个数据项包含多个属性 (例如具有多个属性) 的 XML 元素,默认情况下,节点将显示数据项的 方法返回 ToString 的值。 对于 XML 元素,节点将显示元素名称,该名称显示树的基础结构,但不是非常有用。 通过使用 集合指定树节点绑定 DataBindings ,可以将节点绑定到特定的数据项属性。 集合 DataBindings 包含 TreeNodeBinding 定义数据项与它绑定到的节点之间的关系的对象。 可以指定要在节点中显示的绑定条件和数据项属性。 有关树节点绑定的详细信息,请参阅 TreeNodeBinding

重要

恶意用户可以创建回调请求,并获取页面开发人员未显示的控件节点 TreeView 的数据。 因此,数据的安全性必须由数据源实现。 不要使用 MaxDataBindDepth 属性来隐藏数据。

动态节点填充

有时,静态定义树结构不切实际,因为数据源返回的数据过多,或者要显示的数据取决于在运行时获取的信息。 因此, TreeView 控件支持动态节点填充。 PopulateOnDemand当节点的 属性设置为 true时,将在展开节点时在运行时填充该节点。 若要动态填充节点,必须定义一个事件处理方法,该方法包含用于填充事件节点的 TreeNodePopulate 逻辑。

支持回调脚本的浏览器还可以利用客户端节点填充。 (这包括 Internet Explorer 5.5 及更高版本和其他一些浏览器。) 客户端节点填充使控件能够在 TreeView 用户扩展节点时使用客户端脚本填充节点,而无需往返服务器。 有关客户端节点填充的详细信息,请参阅 PopulateNodesFromClient

自定义用户界面

可通过多种方式自定义控件的外观 TreeView 。 首先,可以为每个节点类型指定不同的样式 (,例如字号和颜色) 。

如果使用级联样式表 (CSS) 来自定义控件的外观,请使用内联样式或单独的 CSS 文件,但不能同时使用这两者。 同时使用内联样式和单独的 CSS 文件可能会导致意外结果。 有关将样式表与控件配合使用的详细信息,请参阅 Web 服务器控件和 CSS 样式

下表列出了可用的节点样式。

节点样式属性 说明
HoverNodeStyle 鼠标指针位于节点上方时的样式设置。
LeafNodeStyle 叶节点的样式设置。
NodeStyle 节点的默认样式设置。
ParentNodeStyle 父节点的样式设置。
RootNodeStyle 根节点的样式设置。
SelectedNodeStyle 所选节点的样式设置。

还可以使用 LevelStyles 集合控制树中特定深度的节点样式。 集合中的第一个样式对应于树中第一个级别的节点的样式。 集合中的第二个样式对应于树中第二级节点的样式,依此而过。 这最常用于生成目录样式导航菜单,其中特定深度的节点应具有相同的外观,无论它们是否有子节点。

注意

如果使用 集合为特定深度级别 LevelStyles 定义了样式,该样式将覆盖该深度节点的任何根、父级或叶节点样式设置。

更改控件外观的另一种方法是自定义控件中显示的 TreeView 图像。 可以通过设置下表所示的属性,为控件的不同部分指定自己的自定义图像集。

Image 属性 说明
CollapseImageUrl 为可折叠节点指示器显示的图像的 URL。 此图像通常是 () 减号。
ExpandImageUrl 为可展开节点指示器显示的图像的 URL。 此图像通常是加号 (+) 。
LineImagesFolder 文件夹的 URL,其中包含用于将父节点连接到子节点的行图像。 还必须 ShowLines 将 属性设置为 true ,此属性才能生效。
NoExpandImageUrl 为不可展开节点指示器显示的图像的 URL。

注意

不需要自定义每个图像属性。 如果未显式设置 image 属性,则使用内置默认映像。

控件TreeView还允许在节点旁边显示检查框。 当 属性ShowCheckBoxes设置为 以外的TreeNodeTypes.None值时,检查框显示在指定的节点类型旁边。

注意

属性 ShowCheckBoxes 可以设置为枚举成员值的按位组合 TreeNodeTypes

每次将页面发布到服务器时,集合会自动 CheckedNodes 填充所选节点。 显示检查框时,每当检查框的状态在发帖到服务器之间发生更改时,都可以使用 TreeNodeCheckChanged 事件来运行自定义例程。

事件

控件 TreeView 提供可对其编程的多个事件。 这样,只要发生事件,就可以运行自定义例程。 下表列出了 控件支持 TreeView 的事件。

事件 说明
TreeNodeCheckChanged 当控件的检查框TreeView在发帖到服务器之间更改状态时发生。
SelectedNodeChanged TreeView 控件中选定某个节点时发生。
TreeNodeExpanded TreeView 控件中展开某个节点时发生。
TreeNodeCollapsed TreeView 控件中折叠某个节点时发生。
TreeNodePopulate 当其 PopulateOnDemand 属性设置为 true 的节点在 TreeView 控件中展开时发生。
TreeNodeDataBound 将数据项绑定到 TreeView 控件中的某个节点时发生。

滚动

控件 TreeView 没有内置滚动功能。 若要添加滚动,请将 TreeView 控件放在 控件中 Panel ,并将滚动条添加到 Panel 控件。 有关详细信息,请参阅 面板 Web 服务器控件概述

可访问性

默认情况下为此控件呈现的标记可能不符合辅助功能标准。 有关此控件的辅助功能支持的详细信息,请参阅 ASP.NET 控件和辅助功能

声明性语法

<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 类的新实例。

属性

AccessKey

获取或设置使您得以快速导航到 Web 服务器控件的访问键。

(继承自 WebControl)
Adapter

获取控件的浏览器特定适配器。

(继承自 Control)
AppRelativeTemplateSourceDirectory

获取或设置包含该控件的 PageUserControl 对象的应用程序相对虚拟目录。

(继承自 Control)
Attributes

获取与控件的特性不对应的任意特性(只用于呈现)的集合。

(继承自 WebControl)
AutoGenerateDataBindings

获取或设置一个值,该值指示 TreeView 控件是否自动生成树节点绑定。

BackColor

获取或设置 Web 服务器控件的背景色。

(继承自 WebControl)
BindingContainer

获取包含该控件的数据绑定的控件。

(继承自 Control)
BorderColor

获取或设置 Web 控件的边框颜色。

(继承自 WebControl)
BorderStyle

获取或设置 Web 服务器控件的边框样式。

(继承自 WebControl)
BorderWidth

获取或设置 Web 服务器控件的边框宽度。

(继承自 WebControl)
CheckedNodes

获取 TreeNode 对象的集合,这些对象表示在 TreeView 控件中显示的选中了复选框的节点。

ChildControlsCreated

获取一个值,该值指示是否已创建服务器控件的子控件。

(继承自 Control)
ClientID

获取由 ASP.NET 生成的 HTML 标记的控件 ID。

(继承自 Control)
ClientIDMode

获取或设置用于生成 ClientID 属性值的算法。

(继承自 Control)
ClientIDSeparator

获取一个字符值,该值表示 ClientID 属性中使用的分隔符字符。

(继承自 Control)
CollapseImageToolTip

获取或设置可折叠节点的指示符所显示图像的工具提示。

CollapseImageUrl

获取或设置自定义图像的 URL,该图像用作可折叠节点的指示符。

Context

为当前 Web 请求获取与服务器控件关联的 HttpContext 对象。

(继承自 Control)
Controls

获取 ControlCollection 对象,该对象表示 UI 层次结构中的指定服务器控件的子控件。

(继承自 Control)
ControlStyle

获取 Web 服务器控件的样式。 此属性主要由控件开发人员使用。

(继承自 WebControl)
ControlStyleCreated

获取一个值,该值指示是否已为 Style 属性创建了 ControlStyle 对象。 此属性主要由控件开发人员使用。

(继承自 WebControl)
CssClass

获取或设置由 Web 服务器控件在客户端呈现的级联样式表 (CSS) 类。

(继承自 WebControl)
DataBindings

获取 TreeNodeBinding 对象的集合,这些对象定义数据项与其绑定到的节点之间的关系。

DataItemContainer

如果命名容器实现 IDataItemContainer,则获取对命名容器的引用。

(继承自 Control)
DataKeysContainer

如果命名容器实现 IDataKeysControl,则获取对命名容器的引用。

(继承自 Control)
DataSource

获取或设置对象,数据绑定控件从该对象中检索其数据项列表。

(继承自 BaseDataBoundControl)
DataSourceID

获取或设置控件的 ID,数据绑定控件从该控件中检索其数据项列表。

(继承自 HierarchicalDataBoundControl)
DesignMode

获取一个值,该值指示是否正在使用设计图面上的一个控件。

(继承自 Control)
EnableClientScript

获取或设置一个值,指示 TreeView 控件是否呈现客户端脚本以处理展开和折叠事件。

Enabled

获取或设置一个值,该值指示是否启用 Web 服务器控件。

(继承自 WebControl)
EnableTheming

获取或设置一个值,该值指示主题是否应用于该控件。

(继承自 WebControl)
EnableViewState

获取或设置一个值,该值指示服务器控件是否向发出请求的客户端保持自己的视图状态以及它所包含的任何子控件的视图状态。

(继承自 Control)
Events

获取控件的事件处理程序委托列表。 此属性为只读。

(继承自 Control)
ExpandDepth

获取或设置第一次显示 TreeView 控件时所展开的层次数。

ExpandImageToolTip

获取或设置可展开节点的指示符所显示图像的工具提示。

ExpandImageUrl

获取或设置自定义图像的 URL,该图像用作可展开节点的指示符。

Font

获取与 Web 服务器控件关联的字体属性。

(继承自 WebControl)
ForeColor

获取或设置 Web 服务器控件的前景色(通常是文本颜色)。

(继承自 WebControl)
HasAttributes

获取一个值,该值指示控件是否具有特性集。

(继承自 WebControl)
HasChildViewState

获取一个值,该值指示当前服务器控件的子控件是否具有任何已保存的视图状态设置。

(继承自 Control)
Height

获取或设置 Web 服务器控件的高度。

(继承自 WebControl)
HoverNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象可用于设置当鼠标指针停在一个节点上时该节点的外观。

ID

获取或设置分配给服务器控件的编程标识符。

(继承自 Control)
IdSeparator

获取用于分隔控件标识符的字符。

(继承自 Control)
ImageSet

获取或设置用于 TreeView 控件的图像组。

Initialized

获取一个值,该值指示数据绑定控件是否已经初始化。

(继承自 BaseDataBoundControl)
IsBoundUsingDataSourceID

获取指示是否设置 DataSourceID 属性的值。

(继承自 BaseDataBoundControl)
IsChildControlStateCleared

获取一个值,该值指示该控件中包含的控件是否具有控件状态。

(继承自 Control)
IsDataBindingAutomatic

获取一个值,该值指示数据绑定是否自动进行。

(继承自 BaseDataBoundControl)
IsEnabled

获取一个值,该值指示是否启用控件。

(继承自 WebControl)
IsTrackingViewState

获取一个值,用于指示服务器控件是否会将更改保存到其视图状态中。

(继承自 Control)
IsUsingModelBinders

在派生类中实现时,获取一个值,该值指示控件是否使用模型联编程序。

(继承自 BaseDataBoundControl)
IsViewStateEnabled

获取一个值,该值指示是否为该控件启用了视图状态。

(继承自 Control)
LeafNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象可用于设置叶节点的外观。

LevelStyles

获取 Style 对象的集合,这些对象表示树中各个级别上的节点样式。

LineImagesFolder

获取或设置文件夹的路径,该文件夹包含用于连接子节点和父节点的线条图像。

LoadViewStateByID

获取一个值,该值指示控件是否通过 ID 而不是索引参与加载其视图状态。

(继承自 Control)
MaxDataBindDepth

获取或设置要绑定到 TreeView 控件的最大树级别数。

NamingContainer

获取对服务器控件的命名容器的引用,此引用创建唯一的命名空间,以区分具有相同 ID 属性值的服务器控件。

(继承自 Control)
NodeIndent

获取或设置 TreeView 控件的子节点的缩进量(以像素为单位)。

Nodes

获取 TreeNode 对象的集合,它表示 TreeView 控件中根节点。

NodeStyle

获取对 TreeNodeStyle 对象的引用,该对象用于设置 TreeView 控件中节点的默认外观。

NodeWrap

获取或设置一个值,它指示空间不足时节点中的文本是否换行。

NoExpandImageUrl

获取或设置自定义图像的 URL,该图像用作不可展开节点的指示符。

Page

获取对包含服务器控件的 Page 实例的引用。

(继承自 Control)
Parent

获取对页 UI 层次结构中服务器控件的父控件的引用。

(继承自 Control)
ParentNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象用于设置 TreeView 控件中父节点的外观。

PathSeparator

获取或设置用于分隔由 ValuePath 属性指定的节点值的字符。

PopulateNodesFromClient

获取或设置一个值,它指示是否按需从客户端填充节点数据。

RenderingCompatibility

获取一个值,该值指定呈现的 HTML 将与之兼容的 ASP.NET 版本。

(继承自 Control)
RequiresDataBinding

获取或设置一个值,该值指示是否应调用 DataBind() 方法。

(继承自 BaseDataBoundControl)
RootNodeStyle

获取对 TreeNodeStyle 对象的引用,该对象用于设置 TreeView 控件中根节点的外观。

SelectedNode

获取表示 TreeNode 控件中选定节点的 TreeView 对象。

SelectedNodeStyle

获取 TreeNodeStyle 对象,该对象控制 TreeView 控件中选定节点的外观。

SelectedValue

获取选定节点的值。

ShowCheckBoxes

获取或设置一个值,它指示哪些节点类型将在 TreeView 控件中显示复选框。

ShowExpandCollapse

获取或设置一个值,它指示是否显示展开节点指示符。

ShowLines

获取或设置一个值,它指示是否显示连接子节点和父节点的线条。

Site

获取容器信息,该容器在呈现于设计图面上时承载当前控件。

(继承自 Control)
SkinID

获取或设置要应用于控件的外观。

(继承自 WebControl)
SkipLinkText

获取或设置一个值,它用于为屏幕读取器呈现替换文字以跳过该控件的内容。

Style

获取将在 Web 服务器控件的外部标记上呈现为样式特性的文本特性的集合。

(继承自 WebControl)
SupportsDisabledAttribute

获取一个值,该值指示在控件的 disabled 属性为 IsEnabled 时,控件是否应将呈现的 HTML 元素的 false 特性设置为 "disabled"。

(继承自 BaseDataBoundControl)
TabIndex

获取或设置 Web 服务器控件的选项卡索引。

(继承自 WebControl)
TagKey

获取 TreeView 控件的 HtmlTextWriterTag 值。

TagName

获取控件标记的名称。 此属性主要由控件开发人员使用。

(继承自 WebControl)
Target

获取或设置要在其中显示与节点相关联的网页内容的目标窗口或框架。

TemplateControl

获取或设置对包含该控件的模板的引用。

(继承自 Control)
TemplateSourceDirectory

获取包含当前服务器控件的 PageUserControl 的虚拟目录。

(继承自 Control)
ToolTip

获取或设置当鼠标指针悬停在 Web 服务器控件上时显示的文本。

(继承自 WebControl)
UniqueID

获取服务器控件的唯一的、以分层形式限定的标识符。

(继承自 Control)
ValidateRequestMode

获取或设置指示控件是否检查来自浏览器的客户端输入是否具有潜在危险值的值。

(继承自 Control)
ViewState

获取状态信息的字典,这些信息使您可以在同一页的多个请求间保存和还原服务器控件的视图状态。

(继承自 Control)
ViewStateIgnoresCase

获取一个值,该值指示 StateBag 对象是否不区分大小写。

(继承自 Control)
ViewStateMode

获取或设置此控件的视图状态模式。

(继承自 Control)
Visible

获取或设置一个值,该值指示控件是否作为 UI 呈现在页上。

Width

获取或设置 Web 服务器控件的宽度。

(继承自 WebControl)

方法

AddAttributesToRender(HtmlTextWriter)

将需要呈现的 HTML 特性和样式添加到指定的 HtmlTextWriter 控件中。

AddedControl(Control, Int32)

在子控件添加到 Control 对象的 Controls 集合后调用。

(继承自 Control)
AddParsedSubObject(Object)

通知服务器控件,分析了一个元素(XML 或 HTML),并将该元素添加到服务器控件的 ControlCollection 对象中。

(继承自 Control)
ApplyStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,覆盖控件的所有现有的样式元素。 此方法主要由控件开发人员使用。

(继承自 WebControl)
ApplyStyleSheetSkin(Page)

将页样式表中定义的样式属性应用到控件。

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

开始输出数据的设计时追踪。

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

收集有关服务器控件的信息并将该信息发送到 Trace 属性,在启用页的跟踪功能时将显示该属性。

(继承自 Control)
ClearCachedClientID()

将缓存的 ClientID 值设置为 null

(继承自 Control)
ClearChildControlState()

删除服务器控件的子控件的控件状态信息。

(继承自 Control)
ClearChildState()

删除服务器控件的所有子控件的视图状态和控件状态信息。

(继承自 Control)
ClearChildViewState()

删除服务器控件的所有子控件的视图状态信息。

(继承自 Control)
ClearEffectiveClientIDMode()

将当前控件实例和任何子控件的 ClientIDMode 属性设置为 Inherit

(继承自 Control)
CollapseAll()

关闭树中的每个节点。

ConfirmInitState()

设置数据绑定控件的初始化状态。

(继承自 BaseDataBoundControl)
CopyBaseAttributes(WebControl)

Style 对象未封装的属性从指定的 Web 服务器控件复制到从中调用此方法的 Web 服务器控件。 此方法主要由控件开发人员使用。

(继承自 WebControl)
CreateChildControls()

由 ASP.NET 页框架调用,以通知服务器控件在准备回发或呈现时使用基于撰写的实现来创建其所包含任何子控件。

(继承自 Control)
CreateControlCollection()

创建用于存储子控件的集合。

CreateControlStyle()

创建由 WebControl 类在内部用来实现所有与样式有关的属性的样式对象。 此方法主要由控件开发人员使用。

(继承自 WebControl)
CreateNode()

返回 TreeNode 类的新实例。 CreateNode() 是一个帮助器方法。

DataBind()

调用基类的 DataBind() 方法。

DataBind(Boolean)

将数据源绑定到调用的服务器控件及其所有子控件,同时可以选择引发 DataBinding 事件。

(继承自 Control)
DataBindChildren()

将数据源绑定到服务器控件的子控件。

(继承自 Control)
Dispose()

使服务器控件得以在从内存中释放之前执行最后的清理操作。

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

结束输出数据的设计时追踪。

(继承自 Control)
EnsureChildControls()

确定服务器控件是否包含子控件。 如果不包含,则创建子控件。

(继承自 Control)
EnsureDataBound()

如果设置了 DataBind() 属性且数据绑定控件标记为需要绑定,则调用 DataSourceID 方法。

(继承自 BaseDataBoundControl)
EnsureID()

为尚未分配标识符的控件创建标识符。

(继承自 Control)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
ExpandAll()

打开树中的每个节点。

FindControl(String)

在当前的命名容器中搜索带指定 id 参数的服务器控件。

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

使用指定的 idpathOffset 参数(该参数有助于搜索)中指定的整数在当前命名容器中搜索服务器控件。 不应重写此版本的 FindControl 方法。

(继承自 Control)
FindNode(String)

检索 TreeNode 控件中指定值路径处的 TreeView 对象。

Focus()

为控件设置输入焦点。

(继承自 Control)
GetCallbackResult()

返回以控件为目标的回调事件的结果。

GetData(String)

检索数据绑定控件用于执行数据操作的 HierarchicalDataSourceView 对象。

(继承自 HierarchicalDataBoundControl)
GetDataSource()

如果存在与数据绑定控件关联的 IHierarchicalDataSource,则检索它。

(继承自 HierarchicalDataBoundControl)
GetDesignModeState()

获取控件的设计时数据。

(继承自 Control)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetRouteUrl(Object)

获取与一组路由参数对应的 URL。

(继承自 Control)
GetRouteUrl(RouteValueDictionary)

获取与一组路由参数对应的 URL。

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

获取与一组路由参数以及某个路由名称对应的 URL。

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

获取与一组路由参数以及某个路由名称对应的 URL。

(继承自 Control)
GetType()

获取当前实例的 Type

(继承自 Object)
GetUniqueIDRelativeTo(Control)

返回指定控件的 UniqueID 属性的前缀部分。

(继承自 Control)
HasControls()

确定服务器控件是否包含任何子控件。

(继承自 Control)
HasEvents()

返回一个值,该值指示是否为控件或任何子控件注册事件。

(继承自 Control)
IsLiteralContent()

确定服务器控件是否只包含文字内容。

(继承自 Control)
LoadControlState(Object)

SaveControlState() 方法保存的上一个页请求还原控件状态信息。

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

处理 TreeView 控件的回发数据。

LoadViewState(Object)

加载以前保存的 TreeView 控件的视图状态。

MapPathSecure(String)

检索虚拟路径(绝对的或相对的)映射到的物理路径。

(继承自 Control)
MarkAsDataBound()

将视图状态中的控件状态设置为成功绑定到数据。

(继承自 HierarchicalDataBoundControl)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MergeStyle(Style)

将指定样式的所有非空白元素复制到 Web 控件,但不覆盖该控件现有的任何样式元素。 此方法主要由控件开发人员使用。

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

确定服务器控件的事件是否沿页的 UI 服务器控件层次结构向上传递。

(继承自 Control)
OnDataBinding(EventArgs)

引发 DataBinding 事件。

(继承自 Control)
OnDataBound(EventArgs)

引发 DataBound 事件。

(继承自 BaseDataBoundControl)
OnDataPropertyChanged()

在其中一个基数据源标识属性更改时被调用,以将数据绑定控件重新绑定到其数据。

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

在与数据绑定控件一起使用的 IHierarchicalDataSource 实例引发 DataSourceChanged 事件时被调用。

(继承自 HierarchicalDataBoundControl)
OnInit(EventArgs)

引发 Init 事件。

OnLoad(EventArgs)

处理 Load 事件。

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

在加载数据绑定控件之前设置该控件的初始化状态。

(继承自 HierarchicalDataBoundControl)
OnPreRender(EventArgs)

引发 PreRender 事件。

OnSelectedNodeChanged(EventArgs)

引发 TreeView 控件的 SelectedNodeChanged 事件。

OnTreeNodeCheckChanged(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeCheckChanged 事件。

OnTreeNodeCollapsed(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeCollapsed 事件。

OnTreeNodeDataBound(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeDataBound 事件。

OnTreeNodeExpanded(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodeExpanded 事件。

OnTreeNodePopulate(TreeNodeEventArgs)

引发 TreeView 控件的 TreeNodePopulate 事件。

OnUnload(EventArgs)

引发 Unload 事件。

(继承自 Control)
OpenFile(String)

获取用于读取文件的 Stream

(继承自 Control)
PerformDataBinding()

基于数据源创建所有节点。

PerformSelect()

从关联的数据源中检索数据。

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

将所有事件源及其信息分配给控件的父级。

(继承自 Control)
RaiseCallbackEvent(String)

使用指定参数引发回调事件。

RaisePostBackEvent(String)

启用 TreeView 控件以处理将窗体发送到服务器时引发的事件。 RaisePostBackEvent(String) 方法是 ICallbackEventHandler.RaiseCallbackEvent(String) 方法的帮助器方法。

RaisePostDataChangedEvent()

TreeView 控件发出信号,以通知 ASP.NET 应用程序该控件的状态已更改。

RemovedControl(Control)

Control 对象的 Controls 集合移除子控件后调用。

(继承自 Control)
Render(HtmlTextWriter)

将控件呈现给指定的 HTML 编写器。

(继承自 WebControl)
RenderBeginTag(HtmlTextWriter)

将控件的 HTML 开始标记呈现到指定的编写器中。

RenderChildren(HtmlTextWriter)

将服务器控件子级的内容输出到提供的 HtmlTextWriter 对象,该对象可写入要在客户端上呈现的内容。

(继承自 Control)
RenderContents(HtmlTextWriter)

呈现 TreeView 控件中的节点。

RenderControl(HtmlTextWriter)

将服务器控件内容输出到所提供的 HtmlTextWriter 对象,如果启用了跟踪,则还将存储有关该控件的跟踪信息。

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

使用提供的 HtmlTextWriter 对象将服务器控件内容输出到提供的 ControlAdapter 对象。

(继承自 Control)
RenderEndTag(HtmlTextWriter)

将控件的 HTML 结束标记呈现到指定的编写器中。

ResolveAdapter()

获取负责呈现指定控件的控件适配器。

(继承自 Control)
ResolveClientUrl(String)

获取浏览器可以使用的 URL。

(继承自 Control)
ResolveUrl(String)

将 URL 转换为在请求客户端可用的 URL。

(继承自 Control)
SaveControlState()

保存将页面回发到服务器之后发生的所有服务器控件状态更改。

(继承自 Control)
SaveViewState()

保存 TreeView 控件的状态。

SetDesignModeState(IDictionary)

为控件设置设计时数据。

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

允许派生类设置指定的 TreeNode 控件是否被数据绑定。

SetNodeDataItem(TreeNode, Object)

允许派生类为指定的 TreeNode 控件设置数据项。

SetNodeDataPath(TreeNode, String)

允许派生类为指定的 TreeNode 控件设置数据路径。

SetRenderMethodDelegate(RenderMethod)

分配事件处理程序委托,以将服务器控件及其内容呈现到父控件中。

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

使用跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

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

使用跟踪对象、跟踪数据键和跟踪数据值,为呈现数据的设计时追踪设置跟踪数据。

(继承自 Control)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
TrackViewState()

跟踪 TreeView 控件的视图状态更改,以便可将它们存储在该控件的 StateBag 对象中。 通过 StateBag 属性可以访问此 ViewState

ValidateDataSource(Object)

验证数据绑定控件绑定到的对象是否可以和该控件一同使用。

(继承自 HierarchicalDataBoundControl)

事件

DataBinding

当服务器控件绑定到数据源时发生。

(继承自 Control)
DataBound

在服务器控件绑定到数据源后发生。

(继承自 BaseDataBoundControl)
Disposed

当从内存释放服务器控件时发生,这是请求 ASP.NET 页时服务器控件生存期的最后阶段。

(继承自 Control)
Init

当服务器控件初始化时发生;初始化是控件生存期的第一步。

(继承自 Control)
Load

当服务器控件加载到 Page 对象中时发生。

(继承自 Control)
PreRender

在加载 Control 对象之后、呈现之前发生。

(继承自 Control)
SelectedNodeChanged

TreeView 控件中选定某个节点时发生。

TreeNodeCheckChanged

TreeView 控件中的复选框在向服务器的两次发送过程之间状态有所更改时发生。

TreeNodeCollapsed

TreeView 控件中折叠某个节点时发生。

TreeNodeDataBound

将数据项绑定到 TreeView 控件中的某个节点时发生。

TreeNodeExpanded

TreeView 控件中展开某个节点时发生。

TreeNodePopulate

当其 PopulateOnDemand 属性设置为 true 的节点在 TreeView 控件中展开时发生。

Unload

当服务器控件从内存中卸载时发生。

(继承自 Control)

显式接口实现

IAttributeAccessor.GetAttribute(String)

获取具有指定名称的 Web 控件的特性。

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

将 Web 控件的特性设置为指定的名称和值。

(继承自 WebControl)
ICallbackEventHandler.GetCallbackResult()

返回以控件为目标的回调事件的结果。

ICallbackEventHandler.RaiseCallbackEvent(String)

使用指定参数引发回调事件。

IControlBuilderAccessor.ControlBuilder

有关此成员的说明,请参见 ControlBuilder

(继承自 Control)
IControlDesignerAccessor.GetDesignModeState()

有关此成员的说明,请参见 GetDesignModeState()

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

有关此成员的说明,请参见 SetDesignModeState(IDictionary)

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

有关此成员的说明,请参见 SetOwnerControl(Control)

(继承自 Control)
IControlDesignerAccessor.UserData

有关此成员的说明,请参见 UserData

(继承自 Control)
IDataBindingsAccessor.DataBindings

有关此成员的说明,请参见 DataBindings

(继承自 Control)
IDataBindingsAccessor.HasDataBindings

有关此成员的说明,请参见 HasDataBindings

(继承自 Control)
IExpressionsAccessor.Expressions

有关此成员的说明,请参见 Expressions

(继承自 Control)
IExpressionsAccessor.HasExpressions

有关此成员的说明,请参见 HasExpressions

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

有关此成员的说明,请参见 AddParsedSubObject(Object)

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

处理 TreeView 控件的回发数据。

IPostBackDataHandler.RaisePostDataChangedEvent()

TreeView 控件发出信号,以通知 ASP.NET 应用程序该控件的状态已更改。

IPostBackEventHandler.RaisePostBackEvent(String)

启用 TreeView 控件以处理将窗体发送到服务器时引发的事件。

扩展方法

EnablePersistedSelection(BaseDataBoundControl)
已过时.

使选定内容能够保留在支持选择和分页的数据控件中。

FindDataSourceControl(Control)

返回与指定控件的数据控件关联的数据源。

FindFieldTemplate(Control, String)

返回指定控件的命名容器中指定列的字段模板。

FindMetaTable(Control)

返回包含数据控件的元表对象。

适用于

另请参阅