Home > Articles > Programming > ASP .NET

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

This chapter is from the book

3.8. Using the Treeview IE Web Control

You want to implement a tree view using the TreeView IE Web Control.

Technique

The first step is to install the IE Web Controls from Microsoft.

The link to download and install these controls is as follows:

http://msdn.microsoft.com/downloads/samples/internet/default.asp? url=/downloads/samples/internet/asp_dot_net_ servercontrols/webcontrols/default.asp

The next step is to add a reference to the controls on your page:

<%@ Register TagPrefix="mytree" 
Namespace="Microsoft.Web.UI.WebControls"
 Assembly="Microsoft.Web.UI.WebControls" %> 
<%@ import namespace="Microsoft.Web.UI.WebControls" %>

Then you add the TreeView control to your page:

<mytree:treeview runat="server" id="myTree"> 
</mytree:treeview>

The last step is to add the node information to the TreeView. This is the list of items that will appear when you expand the tree:

<mytree:treeview runat="server" id="myTree">
 <mytree:treenode text="Cars"> 
  <mytree:treenode text="Ford" />
   <mytree:treenode text="Toyota" />
  <mytree:treenode text="Infiniti" />
   </mytree:treenode>
</mytree:treeview>

Here, we created one node called Cars and then added nodes within that node for different car manufacturers.

Comments

The TreeView IE Web Control is a very powerful and easy-to-use control. In this example, you saw how easy it was to create an explorer-like expandable tree. When adding nodes to the TreeView, you use a very XML-like approach whereby the nodes that are under a parent node are contained inside the parent node tag. If you encounter errors when trying to add a reference to your page, or you receive errors indicating that the Web Controls cannot be found, copy the Web Controls DLL to the bin directory of your application.

See Also

Basics of the TreeView Control— http://www.aspalliance.com/jamesavery/webcontrols/treeviewp1.aspx

Section 3.11, "Data-binding a TreeView Control"

Overview of Treeview Control—http://msdn.microsoft.com/workshop/webcontrols/overview/treeview.asp

  • + Share This
  • 🔖 Save To Your Account