Redigeeri

Jagamisviis:


TreeView Class

Definition

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
[<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
Inheritance
Attributes
Implements

Examples

This section contains seven code examples:

  • The first code example demonstrates how to set up the frames for the second code example.

  • The second code example demonstrates how to use declarative syntax to display static data in the TreeView control.

  • The third code example demonstrates how to bind the TreeView control to an XML data source.

  • The fourth code example provides sample XML data for the third code example.

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

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

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>

The following code example demonstrates how to bind the TreeView control to an XML data source. 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>

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>

The following code example demonstrates how to use the TreeView control for site navigation by binding it to a SiteMapDataSource control. 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>

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>

Remarks

In this topic:

Introduction

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:

  • Data binding that allows the nodes of the control to be bound to XML, tabular, or relational data.

  • Site navigation through integration with the SiteMapDataSource control.

  • Node text that can be displayed as either plain text or hyperlinks.

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

    Note

    The TreeView control is designed to be used inside an UpdatePanel control only when EnableClientScript is set to true. UpdatePanel controls are used to update selected regions of a page instead of updating the whole page with a postback. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.

Nodes

The TreeView control is made up of nodes. 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.

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.

Each node has a Text property and a Value property. 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. To put a node into navigation mode, set the NavigateUrl property for the node to a value other than an empty string (""). To put a node into selection mode, set the NavigateUrl property for the node to an empty string ("").

Note

Some Internet browsers have a limitation that can affect the performance of the TreeView control. For example, Microsoft Internet Explorer 6.0 has a URL character limit of 2067 characters that it posts. 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

The simplest data model of the TreeView control is static data. To display static data using declarative syntax, first nest opening and closing <Nodes> tags between the opening and closing tags of the TreeView control. Next, create the tree structure by nesting <asp:TreeNode> elements between the opening and closing <Nodes> tags. Each <asp:TreeNode> element represents a node in the tree and maps to a TreeNode object. You can set the properties of each node by setting the attributes of its <asp:TreeNode> element. To create child nodes, nest additional <asp:TreeNode> elements between the opening and closing <asp:TreeNode> tags of the parent node.

Binding to Data

The TreeView control can also be bound to data. You can use either of two methods to bind the TreeView control to the appropriate data source type:

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. 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. You can bind a node to a specific data item property by specifying tree node bindings using the DataBindings collection. 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. For more information on tree node bindings, see TreeNodeBinding.

Important

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. 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. Because of this, the TreeView control supports dynamic node population. When the PopulateOnDemand property for a node is set to true, that node gets populated at run time when the node is expanded. 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. (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. For more information on client-side node population, see PopulateNodesFromClient.

Customizing the User Interface

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.

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. Using both inline styles and a separate CSS file could cause unexpected results. 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.

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.

Note

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.

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 property Description
CollapseImageUrl The URL to an image displayed for the collapsible node indicator. This image is usually a minus sign (-).
ExpandImageUrl The URL to an image displayed for the expandable node indicator. This image is usually a plus sign (+).
LineImagesFolder The URL to the folder containing the line images used to connect parent nodes to child nodes. The ShowLines property must also be set to true for this property to have an effect.
NoExpandImageUrl The URL to an image displayed for the non-expandable node indicator.

Note

You do not need to customize every image property. If an image property is not explicitly set, the built-in default image is used.

The TreeView control also allows you to display a check box next to a node. When the ShowCheckBoxes property is set to a value other than TreeNodeTypes.None, check boxes are displayed next to the specified node types.

Note

The ShowCheckBoxes property can be set to a bitwise combination of the TreeNodeTypes enumeration member values.

Each time the page is posted to the server, the CheckedNodes collection is automatically populated with the selected nodes. 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

The TreeView control provides several events that you can program against. This allows you to run a custom routine whenever an event occurs. The following table lists the events that are supported by the TreeView control.

Event Description
TreeNodeCheckChanged Occurs when the check boxes of the TreeView control change state between posts to the server.
SelectedNodeChanged Occurs when a node is selected in the TreeView control.
TreeNodeExpanded Occurs when a node is expanded in the TreeView control.
TreeNodeCollapsed Occurs when a node is collapsed in the TreeView control.
TreeNodePopulate Occurs when a node with its PopulateOnDemand property set to true is expanded in the TreeView control.
TreeNodeDataBound Occurs when a data item is bound to a node in the TreeView control.

Scrolling

The TreeView control does not have built-in scrolling. To add scrolling, place the TreeView control in a Panel control and add scrollbars to the Panel control. For more information, see Panel Web Server Control Overview.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards. 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>

Constructors

TreeView()

Initializes a new instance of the TreeView class.

Properties

AccessKey

Gets or sets the access key that allows you to quickly navigate to the Web server control.

(Inherited from WebControl)
Adapter

Gets the browser-specific adapter for the control.

(Inherited from Control)
AppRelativeTemplateSourceDirectory

Gets or sets the application-relative virtual directory of the Page or UserControl object that contains this control.

(Inherited from Control)
Attributes

Gets the collection of arbitrary attributes (for rendering only) that do not correspond to properties on the control.

(Inherited from WebControl)
AutoGenerateDataBindings

Gets or sets a value indicating whether the TreeView control automatically generates tree node bindings.

BackColor

Gets or sets the background color of the Web server control.

(Inherited from WebControl)
BindingContainer

Gets the control that contains this control's data binding.

(Inherited from Control)
BorderColor

Gets or sets the border color of the Web control.

(Inherited from WebControl)
BorderStyle

Gets or sets the border style of the Web server control.

(Inherited from WebControl)
BorderWidth

Gets or sets the border width of the Web server control.

(Inherited from WebControl)
CheckedNodes

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.

(Inherited from Control)
ClientID

Gets the control ID for HTML markup that is generated by ASP.NET.

(Inherited from Control)
ClientIDMode

Gets or sets the algorithm that is used to generate the value of the ClientID property.

(Inherited from Control)
ClientIDSeparator

Gets a character value representing the separator character used in the ClientID property.

(Inherited from Control)
CollapseImageToolTip

Gets or sets the ToolTip for the image that is displayed for the collapsible node indicator.

CollapseImageUrl

Gets or sets the URL to a custom image for the collapsible node indicator.

Context

Gets the HttpContext object associated with the server control for the current Web request.

(Inherited from Control)
Controls

Gets a ControlCollection object that represents the child controls for a specified server control in the UI hierarchy.

(Inherited from Control)
ControlStyle

Gets the style of the Web server control. This property is used primarily by control developers.

(Inherited from WebControl)
ControlStyleCreated

Gets a value indicating whether a Style object has been created for the ControlStyle property. This property is primarily used by control developers.

(Inherited from WebControl)
CssClass

Gets or sets the Cascading Style Sheet (CSS) class rendered by the Web server control on the client.

(Inherited from WebControl)
DataBindings

Gets a collection of TreeNodeBinding objects that define the relationship between a data item and the node that it is binding to.

DataItemContainer

Gets a reference to the naming container if the naming container implements IDataItemContainer.

(Inherited from Control)
DataKeysContainer

Gets a reference to the naming container if the naming container implements IDataKeysControl.

(Inherited from Control)
DataSource

Gets or sets the object from which the data-bound control retrieves its list of data items.

(Inherited from BaseDataBoundControl)
DataSourceID

Gets or sets the ID of the control from which the data-bound control retrieves its list of data items.

(Inherited from HierarchicalDataBoundControl)
DesignMode

Gets a value indicating whether a control is being used on a design surface.

(Inherited from Control)
EnableClientScript

Gets or sets a value indicating whether the TreeView control renders client-side script to handle expanding and collapsing events.

Enabled

Gets or sets a value indicating whether the Web server control is enabled.

(Inherited from WebControl)
EnableTheming

Gets or sets a value indicating whether themes apply to this control.

(Inherited from 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.

(Inherited from Control)
Events

Gets a list of event handler delegates for the control. This property is read-only.

(Inherited from Control)
ExpandDepth

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

Gets or sets the URL to a custom image for the expandable node indicator.

Font

Gets the font properties associated with the Web server control.

(Inherited from WebControl)
ForeColor

Gets or sets the foreground color (typically the color of the text) of the Web server control.

(Inherited from WebControl)
HasAttributes

Gets a value indicating whether the control has attributes set.

(Inherited from WebControl)
HasChildViewState

Gets a value indicating whether the current server control's child controls have any saved view-state settings.

(Inherited from Control)
Height

Gets or sets the height of the Web server control.

(Inherited from WebControl)
HoverNodeStyle

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.

(Inherited from Control)
IdSeparator

Gets the character used to separate control identifiers.

(Inherited from Control)
ImageSet

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.

(Inherited from BaseDataBoundControl)
IsBoundUsingDataSourceID

Gets a value indicating whether the DataSourceID property is set.

(Inherited from BaseDataBoundControl)
IsChildControlStateCleared

Gets a value indicating whether controls contained within this control have control state.

(Inherited from Control)
IsDataBindingAutomatic

Gets a value that indicates whether data binding is automatic.

(Inherited from BaseDataBoundControl)
IsEnabled

Gets a value indicating whether the control is enabled.

(Inherited from WebControl)
IsTrackingViewState

Gets a value that indicates whether the server control is saving changes to its view state.

(Inherited from Control)
IsUsingModelBinders

When implemented in a derived class, gets a value that indicates whether the control is using model binders.

(Inherited from BaseDataBoundControl)
IsViewStateEnabled

Gets a value indicating whether view state is enabled for this control.

(Inherited from Control)
LeafNodeStyle

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of leaf nodes.

LevelStyles

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

Gets a value indicating whether the control participates in loading its view state by ID instead of index.

(Inherited from Control)
MaxDataBindDepth

Gets or sets the maximum number of tree levels to bind to the TreeView control.

NamingContainer

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.

(Inherited from Control)
NodeIndent

Gets or sets the indentation amount (in pixels) for the child nodes of the TreeView control.

Nodes

Gets a collection of TreeNode objects that represents the root nodes in the TreeView control.

NodeStyle

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

Gets or sets the URL to a custom image for the non-expandable node indicator.

Page

Gets a reference to the Page instance that contains the server control.

(Inherited from Control)
Parent

Gets a reference to the server control's parent control in the page control hierarchy.

(Inherited from Control)
ParentNodeStyle

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of parent nodes in the TreeView control.

PathSeparator

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

Gets a value that specifies the ASP.NET version that rendered HTML will be compatible with.

(Inherited from Control)
RequiresDataBinding

Gets or sets a value indicating whether the DataBind() method should be called.

(Inherited from BaseDataBoundControl)
RootNodeStyle

Gets a reference to the TreeNodeStyle object that allows you to set the appearance of the root node in the TreeView control.

SelectedNode

Gets a TreeNode object that represents the selected node in the TreeView control.

SelectedNodeStyle

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

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.

(Inherited from Control)
SkinID

Gets or sets the skin to apply to the control.

(Inherited from 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

Gets a collection of text attributes that will be rendered as a style attribute on the outer tag of the Web server control.

(Inherited from WebControl)
SupportsDisabledAttribute

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.

(Inherited from BaseDataBoundControl)
TabIndex

Gets or sets the tab index of the Web server control.

(Inherited from WebControl)
TagKey

Gets the HtmlTextWriterTag value for the TreeView control.

TagName

Gets the name of the control tag. This property is used primarily by control developers.

(Inherited from 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.

(Inherited from Control)
TemplateSourceDirectory

Gets the virtual directory of the Page or UserControl that contains the current server control.

(Inherited from Control)
ToolTip

Gets or sets the text displayed when the mouse pointer hovers over the Web server control.

(Inherited from WebControl)
UniqueID

Gets the unique, hierarchically qualified identifier for the server control.

(Inherited from Control)
ValidateRequestMode

Gets or sets a value that indicates whether the control checks client input from the browser for potentially dangerous values.

(Inherited from 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.

(Inherited from Control)
ViewStateIgnoresCase

Gets a value that indicates whether the StateBag object is case-insensitive.

(Inherited from Control)
ViewStateMode

Gets or sets the view-state mode of this control.

(Inherited from Control)
Visible

Gets or sets a value indicating whether the control is rendered as UI on the page.

Width

Gets or sets the width of the Web server control.

(Inherited from WebControl)

Methods

AddAttributesToRender(HtmlTextWriter)

Adds HTML attributes and styles that need to be rendered to the specified HtmlTextWriter control.

AddedControl(Control, Int32)

Called after a child control is added to the Controls collection of the Control object.

(Inherited from Control)
AddParsedSubObject(Object)

Notifies the server control that an element, either XML or HTML, was parsed, and adds the element to the server control's ControlCollection object.

(Inherited from Control)
ApplyStyle(Style)

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.

(Inherited from WebControl)
ApplyStyleSheetSkin(Page)

Applies the style properties defined in the page style sheet to the control.

(Inherited from Control)
BeginRenderTracing(TextWriter, Object)

Begins design-time tracing of rendering data.

(Inherited from Control)
BuildProfileTree(String, Boolean)

Gathers information about the server control and delivers it to the Trace property to be displayed when tracing is enabled for the page.

(Inherited from Control)
ClearCachedClientID()

Sets the cached ClientID value to null.

(Inherited from Control)
ClearChildControlState()

Deletes the control-state information for the server control's child controls.

(Inherited from Control)
ClearChildState()

Deletes the view-state and control-state information for all the server control's child controls.

(Inherited from Control)
ClearChildViewState()

Deletes the view-state information for all the server control's child controls.

(Inherited from Control)
ClearEffectiveClientIDMode()

Sets the ClientIDMode property of the current control instance and of any child controls to Inherit.

(Inherited from Control)
CollapseAll()

Closes every node in the tree.

ConfirmInitState()

Sets the initialized state of the data-bound control.

(Inherited from BaseDataBoundControl)
CopyBaseAttributes(WebControl)

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.

(Inherited from WebControl)
CreateChildControls()

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.

(Inherited from Control)
CreateControlCollection()

Creates a collection to store child controls.

CreateControlStyle()

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.

(Inherited from WebControl)
CreateNode()

Returns a new instance of the TreeNode class. The CreateNode() is a helper method.

DataBind()

Calls the DataBind() method of the base class.

DataBind(Boolean)

Binds a data source to the invoked server control and all its child controls with an option to raise the DataBinding event.

(Inherited from Control)
DataBindChildren()

Binds a data source to the server control's child controls.

(Inherited from Control)
Dispose()

Enables a server control to perform final clean up before it is released from memory.

(Inherited from Control)
EndRenderTracing(TextWriter, Object)

Ends design-time tracing of rendering data.

(Inherited from Control)
EnsureChildControls()

Determines whether the server control contains child controls. If it does not, it creates child controls.

(Inherited from Control)
EnsureDataBound()

Calls the DataBind() method if the DataSourceID property is set and the data-bound control is marked to require binding.

(Inherited from BaseDataBoundControl)
EnsureID()

Creates an identifier for controls that do not have an identifier assigned.

(Inherited from Control)
Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
ExpandAll()

Opens every node in the tree.

FindControl(String, Int32)

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. You should not override this version of the FindControl method.

(Inherited from Control)
FindControl(String)

Searches the current naming container for a server control with the specified id parameter.

(Inherited from Control)
FindNode(String)

Retrieves the TreeNode object in the TreeView control at the specified value path.

Focus()

Sets input focus to a control.

(Inherited from Control)
GetCallbackResult()

Returns the result of a callback event that targets a control.

GetData(String)

Retrieves a HierarchicalDataSourceView object that the data-bound control uses to perform data operations.

(Inherited from HierarchicalDataBoundControl)
GetDataSource()

Retrieves the IHierarchicalDataSource that the data-bound control is associated with, if any.

(Inherited from HierarchicalDataBoundControl)
GetDesignModeState()

Gets design-time data for a control.

(Inherited from Control)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetRouteUrl(Object)

Gets the URL that corresponds to a set of route parameters.

(Inherited from Control)
GetRouteUrl(RouteValueDictionary)

Gets the URL that corresponds to a set of route parameters.

(Inherited from Control)
GetRouteUrl(String, Object)

Gets the URL that corresponds to a set of route parameters and a route name.

(Inherited from Control)
GetRouteUrl(String, RouteValueDictionary)

Gets the URL that corresponds to a set of route parameters and a route name.

(Inherited from Control)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUniqueIDRelativeTo(Control)

Returns the prefixed portion of the UniqueID property of the specified control.

(Inherited from Control)
HasControls()

Determines if the server control contains any child controls.

(Inherited from Control)
HasEvents()

Returns a value indicating whether events are registered for the control or any child controls.

(Inherited from Control)
IsLiteralContent()

Determines if the server control holds only literal content.

(Inherited from Control)
LoadControlState(Object)

Restores control-state information from a previous page request that was saved by the SaveControlState() method.

(Inherited from Control)
LoadPostData(String, NameValueCollection)

Processes postback data for the TreeView control.

LoadViewState(Object)

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.

(Inherited from Control)
MarkAsDataBound()

Sets the state of the control in view state as successfully bound to data.

(Inherited from HierarchicalDataBoundControl)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MergeStyle(Style)

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.

(Inherited from WebControl)
OnBubbleEvent(Object, EventArgs)

Determines whether the event for the server control is passed up the page's UI server control hierarchy.

(Inherited from Control)
OnDataBinding(EventArgs)

Raises the DataBinding event.

(Inherited from Control)
OnDataBound(EventArgs)

Raises the DataBound event.

(Inherited from BaseDataBoundControl)
OnDataPropertyChanged()

Called when one of the base data source identification properties is changed, to re-bind the data-bound control to its data.

(Inherited from HierarchicalDataBoundControl)
OnDataSourceChanged(Object, EventArgs)

Called when the IHierarchicalDataSource instance that the data-bound control works with raises the DataSourceChanged event.

(Inherited from HierarchicalDataBoundControl)
OnInit(EventArgs)

Raises the Init event.

OnLoad(EventArgs)

Handles the Load event.

(Inherited from HierarchicalDataBoundControl)
OnPagePreLoad(Object, EventArgs)

Sets the initialized state of the data-bound control before the control is loaded.

(Inherited from HierarchicalDataBoundControl)
OnPreRender(EventArgs)

Raises the PreRender event.

OnSelectedNodeChanged(EventArgs)

Raises the SelectedNodeChanged event of the TreeView control.

OnTreeNodeCheckChanged(TreeNodeEventArgs)

Raises the TreeNodeCheckChanged event of the TreeView control.

OnTreeNodeCollapsed(TreeNodeEventArgs)

Raises the TreeNodeCollapsed event of the TreeView control.

OnTreeNodeDataBound(TreeNodeEventArgs)

Raises the TreeNodeDataBound event of the TreeView control.

OnTreeNodeExpanded(TreeNodeEventArgs)

Raises the TreeNodeExpanded event of the TreeView control.

OnTreeNodePopulate(TreeNodeEventArgs)

Raises the TreeNodePopulate event of the TreeView control.

OnUnload(EventArgs)

Raises the Unload event.

(Inherited from Control)
OpenFile(String)

Gets a Stream used to read a file.

(Inherited from Control)
PerformDataBinding()

Creates all the nodes based on the data source.

PerformSelect()

Retrieves data from the associated data source.

(Inherited from HierarchicalDataBoundControl)
RaiseBubbleEvent(Object, EventArgs)

Assigns any sources of the event and its information to the control's parent.

(Inherited from Control)
RaiseCallbackEvent(String)

Raises the callback event using the specified arguments.

RaisePostBackEvent(String)

Enables the TreeView control to process an event that is raised when a form is posted to the server. The RaisePostBackEvent(String) method is a helper method for the ICallbackEventHandler.RaiseCallbackEvent(String) method.

RaisePostDataChangedEvent()

Signals the TreeView control to notify the ASP.NET application that the state of the control has changed.

RemovedControl(Control)

Called after a child control is removed from the Controls collection of the Control object.

(Inherited from Control)
Render(HtmlTextWriter)

Renders the control to the specified HTML writer.

(Inherited from WebControl)
RenderBeginTag(HtmlTextWriter)

Renders the HTML opening tag of the control to the specified writer.

RenderChildren(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.

(Inherited from Control)
RenderContents(HtmlTextWriter)

Renders the nodes in the TreeView control.

RenderControl(HtmlTextWriter, ControlAdapter)

Outputs server control content to a provided HtmlTextWriter object using a provided ControlAdapter object.

(Inherited from Control)
RenderControl(HtmlTextWriter)

Outputs server control content to a provided HtmlTextWriter object and stores tracing information about the control if tracing is enabled.

(Inherited from Control)
RenderEndTag(HtmlTextWriter)

Renders the HTML closing tag of the control to the specified writer.

ResolveAdapter()

Gets the control adapter responsible for rendering the specified control.

(Inherited from Control)
ResolveClientUrl(String)

Gets a URL that can be used by the browser.

(Inherited from Control)
ResolveUrl(String)

Converts a URL into one that is usable on the requesting client.

(Inherited from Control)
SaveControlState()

Saves any server control state changes that have occurred since the time the page was posted back to the server.

(Inherited from Control)
SaveViewState()

Saves the state of the TreeView control.

SetDesignModeState(IDictionary)

Sets design-time data for a control.

(Inherited from Control)
SetNodeDataBound(TreeNode, Boolean)

Allows a derived class to set whether the specified TreeNode control is data-bound.

SetNodeDataItem(TreeNode, Object)

Allows a derived class to set the data item for the specified TreeNode control.

SetNodeDataPath(TreeNode, String)

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.

(Inherited from 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.

(Inherited from Control)
SetTraceData(Object, Object)

Sets trace data for design-time tracing of rendering data, using the trace data key and the trace data value.

(Inherited from Control)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
TrackViewState()

Tracks view-state changes to the TreeView control so that they can be stored in the StateBag object for the control. This 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.

(Inherited from HierarchicalDataBoundControl)

Events

DataBinding

Occurs when the server control binds to a data source.

(Inherited from Control)
DataBound

Occurs after the server control binds to a data source.

(Inherited from BaseDataBoundControl)
Disposed

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.

(Inherited from Control)
Init

Occurs when the server control is initialized, which is the first step in its lifecycle.

(Inherited from Control)
Load

Occurs when the server control is loaded into the Page object.

(Inherited from Control)
PreRender

Occurs after the Control object is loaded but prior to rendering.

(Inherited from Control)
SelectedNodeChanged

Occurs when a node is selected in the TreeView control.

TreeNodeCheckChanged

Occurs when a check box in the TreeView control changes state between posts to the server.

TreeNodeCollapsed

Occurs when a node is collapsed in the TreeView control.

TreeNodeDataBound

Occurs when a data item is bound to a node in the TreeView control.

TreeNodeExpanded

Occurs when a node is expanded in the TreeView control.

TreeNodePopulate

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.

(Inherited from Control)

Explicit Interface Implementations

IAttributeAccessor.GetAttribute(String)

Gets an attribute of the Web control with the specified name.

(Inherited from WebControl)
IAttributeAccessor.SetAttribute(String, String)

Sets an attribute of the Web control to the specified name and value.

(Inherited from 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

For a description of this member, see ControlBuilder.

(Inherited from Control)
IControlDesignerAccessor.GetDesignModeState()

For a description of this member, see GetDesignModeState().

(Inherited from Control)
IControlDesignerAccessor.SetDesignModeState(IDictionary)

For a description of this member, see SetDesignModeState(IDictionary).

(Inherited from Control)
IControlDesignerAccessor.SetOwnerControl(Control)

For a description of this member, see SetOwnerControl(Control).

(Inherited from Control)
IControlDesignerAccessor.UserData

For a description of this member, see UserData.

(Inherited from Control)
IDataBindingsAccessor.DataBindings

For a description of this member, see DataBindings.

(Inherited from Control)
IDataBindingsAccessor.HasDataBindings

For a description of this member, see HasDataBindings.

(Inherited from Control)
IExpressionsAccessor.Expressions

For a description of this member, see Expressions.

(Inherited from Control)
IExpressionsAccessor.HasExpressions

For a description of this member, see HasExpressions.

(Inherited from Control)
IParserAccessor.AddParsedSubObject(Object)

For a description of this member, see AddParsedSubObject(Object).

(Inherited from Control)
IPostBackDataHandler.LoadPostData(String, NameValueCollection)

Processes postback data for the TreeView control.

IPostBackDataHandler.RaisePostDataChangedEvent()

Signals the TreeView control to notify the ASP.NET application that the state of the control has changed.

IPostBackEventHandler.RaisePostBackEvent(String)

Enables the TreeView control to process an event that is raised when a form is posted to the server.

Extension Methods

EnablePersistedSelection(BaseDataBoundControl)
Obsolete.

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.

Applies to

See also