Controls You Can Use on Web Forms ASP.NET Navigation Controls TreeView Control
The TreeView control exposes a Nodes collection, which comprise the root TreeNode objects defined for the control.
In the same manner, each TreeNode object exposes a ChildNodes collection, which comprise the child TreeNode objects, if any, defined for that particular node.
Root treeview nodes can be configured programmatically, by creating new instances of the TreeNode class and adding them to the Nodes collection in the order that they will appear in the treeview structure.
Likewise, child treeview nodes can be configured programmatically, by creating new instances of the TreeNode class and adding them to the ChildNodes collection of the parent node, in the order that they will appear in the treeview structure.
To display data dynamically, the TreeView control supports dynamic node population. When the TreeView control is configured to populate on demand ( the PopulateOnDemand property for a node is set to true ), the control raises a TreeNodePopulate event when the node is expanded, to which you can respond to accordingly.
- Set the PopulateOnDemand property of a node to true
- Define a method to handle the TreeNodePopulate event.
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
The following examples demonstrate how to populate the nodes of a TreeView control dynamically.
Binding a TreeView Control to a Data Source Customizing the TreeView Control User Interface