- Introduction
- Declaring a Simple Custom Control
- Extending Existing Web Controls
- Creating ViewState-Enabled Control Properties
- Creating a Composite Control
- Creating a Data-bound Control
- Creating a Templated Control
- Dynamically Adding Controls to a Web Form
- Using the Treeview IE Web Control
- Using the TabControl and PageView IE Web Controls
- Using the ToolBar IE Web Control
- Data-binding a TreeView Control
- Installing a Component in the Global Assembly Cache (GAC)
3.11. Data-binding a TreeView Control
You want to populate a treeview with data by using XML and the TreeView IE Web Control.
Technique
If you have not worked with the TreeView control before, refer to section 3.8 for basic TreeView information.
First, you need to add the TreeView to your page and set the treenodesrc property to the XML file that you'll be creating.
<mytree:treeview runat="server" id="myTree" treenodesrc="cars.XML"> </mytree:treeview>
The next thing you need to do is create your XML file that you will use to bind the TreeView to:
<?xml version="1.0" encoding="utf-8" ?> <TREENODES> <treenode text="Cars"> <treenode text="Ford" /> <treenode text="Toyota" /> <treenode text="Infiniti" /> </treenode> </TREENODES>
When the page loads, the TreeView will generate its nodes from the XML file.
Comments
It is not possible to directly data-bind a dataset to the TreeView Web Control. The data must first be translated to XML. You can use response.write, which writes the XML, or use XSLT to transform the dataset into the correct XML. When using XSLT, you can specify the XSLT file using the TreeNodeXsltSrc property of the TreeView. In addition to using XML to define the actual nodes of the TreeView, you can also use XML to define the style types by using the TreeNodeTypeSrc property of the TreeView control.
See Also
Overview of Treeview Controlhttp://msdn.microsoft.com/workshop/webcontrols/overview/treeview.asp
Creating Dynamic TreeViewshttp://www.aspalliance.com/jamesavery/webcontrols/treeviewp2.aspx