You can use the ASP. NET Treeview control to easily bind a data source that supports the ihierarchicaldatasource interface, such as the xmldatasource class and sitemapdatasource class. In addition, you can fully control which fields of the data source are used for text, value, and other treenode attributes.
1. bind to an XML file
The Treeview control supports declarative binding to XML files (by using the xmldatasource control ). Create an xmldatasource control that represents an XML file and allocate the xmldatasource to the Treeview control. You can bind the Treeview control to the XML file. In addition, some technologies can be used to control the data binding method and data content bound to the Treeview control, including the following technologies:
If the data source is an XML file, modify the data by performing XML Conversion before binding the XML file to the control. For more information, see XSLT conversion.
Create a custom databindings attribute to control which attributes in the XML file will fill the treenode attribute, such as the text attribute, value attribute, and navigateurl attribute. For more information, see customize the appearance of the Treeview Web Server Control.
2. bind to the Site Map
The Treeview control supports declarative binding to site map files by using the sitemapdatasource control ). When bound to an instance of the sitemapdatasource control, the title and URL attributes of each sitemapnode are automatically associated with the text and navigateurl attributes of each treenode object in the Treeview control, so you do not need to create custom data binding.
3. Fill nodes
That is, the padding function allows you to specify that the data filling node is not used when the Treeview control is initially rendered. Instead, the treenode control requests data from the subnode when you click the node. When the populateondemand attribute of the treenode control is set to true, a treenodepopulate event occurs if you click and expand the node. You can create an event handler to Dynamically Retrieve data when a treenodepopulate event is triggered, so that tree data can be retrieved as needed.
4. Non-declarative Data Binding
In addition to using the derived class of performancecontrol to transparently bind data to the Treeview control, the Treeview control also provides the datasource attribute and the databind Method for Data Binding.