Binding Data to the TreeView Web Server Control
The ASP.NET TreeView control makes it easy to bind to a data source that supports theinterface, 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.
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 customproperty 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 .
For more information about binding to an XML file, see. 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, theand 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 theproperty 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 .
Non-Declarative Data Binding
In addition to using a class that derives fromto declaratively bind data to the TreeView control, the TreeView control provides a property and a method for data binding.