ASP. NET-bind data to the Treeview Web Server Control

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.