The ASP.NET TreeView control makes it easy to bind to a data source that supports the interface, such as the class and the class. Additionally, you have complete control over which fields of the data source are used for the , , and other properties.
For more information, see TreeView Web Server Control Overview.
Binding to an XML File
The TreeView control supports declarative binding to an XML file by using XmlDataSource controls. You can bind a TreeView control to an XML file by creating an XmlDataSource control that represents the XML file and then assigning that XmlDataSource to your TreeView control. Furthermore, you can control how and what data is bound to the TreeView control by using several techniques, which include the following:
If the data source is an XML file, alter the data by performing an XML transformation before the XML file is bound to the control. For more information, see .
Create a custom property that controls which fields in the XML file populate the TreeNode properties, such as the Text property, the Value property, the property, and others. For more information, see Customizing the Look and Feel of the TreeView Web Server Control.
For more information about binding to an XML file, see Binding to Hierarchical Data. For a step-by-step example, see .
Binding to a Site Map
The TreeView control supports declarative binding to a site-map file by using SiteMapDataSource controls. When binding to an instance of the SiteMapDataSource control, the and properties of each are automatically associated with the Text and NavigateUrl properties of each TreeNode object in the TreeView control, so there is no need to create custom data bindings. For more information and an example of binding a TreeView control to a site map, see .
Populating Nodes on Demand
The populate-on-demand feature allows you to specify that a node not be populated with data when the TreeView control initially renders. Instead, the TreeNode control will request child-node data when a user clicks the node. When the property of a TreeNode control is set to true, the event occurs when a user clicks the node to expand it. You can create an event handler to retrieve data dynamically when the TreeNodePopulate event is raised, which allows tree data to be retrieved as needed. For more information, see Server Event Handling in ASP.NET Web Pages.
Non-Declarative Data Binding
In addition to using a class that derives from to declaratively bind data to the TreeView control, the TreeView control provides a property and a method for data binding.