Home > Articles > Programming > ASP .NET

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

3.11. Data-binding a TreeView Control

You want to populate a treeview with data by using XML and the TreeView IE Web Control.


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">

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" ?> 
 <treenode text="Cars"> 
  <treenode text="Ford" /> 
  <treenode text="Toyota" /> 
  <treenode text="Infiniti" /> 

When the page loads, the TreeView will generate its nodes from the XML file.


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.

Creating Dynamic TreeViews—http://www.aspalliance.com/jamesavery/webcontrols/treeviewp2.aspx

  • + Share This
  • 🔖 Save To Your Account