This documentation is archived and is not being maintained.

TreeNodeBinding.PopulateOnDemand Property

Gets or sets a value indicating whether the node to which the TreeNodeBinding object is applied is populated dynamically.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

public bool PopulateOnDemand { get; set; }

Property Value

Type: System.Boolean
true to populate the node to which the TreeNodeBinding object is applied dynamically; otherwise, false. The default is false.

Sometimes, it is not practical to statically predefine the tree structure due to data size or custom content that depends on user input. Because of this, the TreeView control supports dynamic node population. When the PopulateOnDemand property is set to true, the child nodes of the node that the TreeNodeBinding object is applied to gets populated at run time when the node is expanded.

When data bindings are created by setting the AutoGenerateDataBindings of the TreeView control to true, the bindings that are created have the PopulateOnDemand property set to true. Data bindings that are created declaratively have the PopulateOnDemand property set to false. Using the declarative syntax allows you to control the behavior of individual data bindings.


Unlike the PopulateOnDemand property of the TreeNode class, the PopulateOnDemand property does not require an event-handling method to be defined for the TreeNodePopulate event, if you are using a data source control, such as XmlDataSource. Instead, the TreeView control dynamically generates an event-handling method using the properties of the TreeNodeBinding objects in the DataBindings collection. You can still define an event-handling method for the TreeNodePopulate event; however, it will be called after the event-handling method for the TreeView control.

Supported browsers can also take advantage of client-side node population. When enabled, this allows the TreeView control to populate a node dynamically on the client when that node is expanded, preventing the need to post back to the server. For more information on client-side node population, see PopulateNodesFromClient.

The value of this property is stored in view state.

This section contains two code examples. The first code example demonstrates how to use the ShowCheckBox property to specify whether a check box is displayed for a node. The second code example provides sample XML data for the first code example.

The following example demonstrates how to use the ShowCheckBox property to specify whether a check box is displayed for a node. 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"
<script runat="server">

  void Page_Load(Object sender, EventArgs e)

    // Create a TreeNodeBinding object and set its 
    // properties.
    TreeNodeBinding binding = new TreeNodeBinding();
    binding.DataMember = "Section";
    binding.Depth = 2;
    binding.TextField = "Heading";

    // Set the PopulateOnDemand property of the
    // TreeNodeBinding object programmatically.
    binding.PopulateOnDemand = false;

    // Add the TreeNodeBinding object to the DataBindings
    // collection of the TreeView control.



<html xmlns="" >
  <head runat="server">
    <title>TreeNodeBinding PopulateOnDemand Example</title>
    <form id="form1" runat="server">

      <h3>TreeNodeBinding PopulateOnDemand Example</h3>

      <asp:TreeView id="BookTreeView" 

          <asp:TreeNodeBinding DataMember="Book" 
          <asp:TreeNodeBinding DataMember="Chapter" 
          <asp:TreeNodeBinding DataMember="Section" 


      <asp:XmlDataSource id="BookXmlDataSource"  


The following code example provides sample XML data for the preceding code example.

<Book Title="Book Title">
    <Chapter Heading="Chapter 1">
        <Section Heading="Section 1">
        <Section Heading="Section 2">
    <Chapter Heading="Chapter 2">
        <Section Heading="Section 1">
    <Appendix Heading="Appendix A">

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.