System.Web.UI.WebControls Namespace TreeView Class
.NET Framework version 2.0
Sets or retrieves a value indicating whether node data for a TreeView control is populated on demand from the client.
Inline |
<asp:treeview populatenodesfromclient = = true | false ... > |
Script |
TreeView.PopulateNodesFromClient [ = true | false ] |
This property accepts or returns only a boolean value: true to populate tree node data on demand from the client; otherwise, false. Default value is true.
Use the PopulateNodesFromClient property to specify whether node data for a TreeView control is populated on demand from the client.
There are cases where it is not practical to statically predefine the tree structure due to data size or custom content that depends on user input. For these cases, 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.
In addition to populating nodes on demand, it is possible to populate the nodes directly on a supported client browser. When the PopulateNodesFromClient property is set to true, a service is called from the client to populate the tree nodes, which eliminates the need to post back to the server. Otherwise, the TreeView control posts back to the server to populate the nodes.
NOTE: The EnableClientScript property must also be set to true in order for the PopulateNodesFromClient property to be set to true.
To populate a node on the client, first set the PopulateNodesFromClient property to true and then set the PopulateOnDemand property for the node to true. Next, define an event-handling method for the TreeNodePopulate event that programmatically populates the node.
The method assigned to handle the event should be able to do the following:
- retrieve node data from a data source
- for each row of data in the source, create a TreeNode object
- bind the data into the node object
- set the node's properties
- add the node structure to the ChildNodes collection of the node being populated
NOTE: When the PopulateOnDemand property for a node is set to true, the node must be populated dynamically. You cannot declaratively nest another node below it; otherwise, an error will occur on the page.
NOTE: The client-side node population feature is supported only in Microsoft Internet Explorer version 5.5 and later and Netscape 6.0 and later.
The following examples demonstrate how to use the PopulateNodesFromClient property to render client-side script that is used to expand and collapse nodes on compatible browsers.
TreeView Members