SQL    
 
database database
spacer
spacer Aboutspacer Contact Us Free Tour Homespacer Joinspacer Member Login Price spacer
spacer spacer  
 

Populating the TreeView Control from a Database 3

Checkbox

We can generate two very different feels for the control by using the "Checkbox" property.

TreeView

 

Checkboxes are controlled at the node level by including "checkbox true" into the node line:

<iewc:TreeNode CheckBox="True" Text="Child1"></iewc:TreeNode>

In Visual Studio, the checkbox property is found in the Appearance area in the TreeNodeEditor.

  TreeView
 

 

XML

Before going into database binding, we'll look at XML because it's probably the most common way to bind data to a TreeView. This time, we will use the TreeNodeSrc attribute and static XML file to create the Parent Child structure of our tree.

Create the following XML file called XMLFile1.xml and save it in the same directory as your TreeView aspx file.


<TREENODES>
<treenode text="Partent1">
<treenode text="Child-1a"/>
<treenode text="Child-1b"/>
</treenode>
<treenode text="Partent2">
<treenode text="Child-2a"/>
<treenode text="Child-2b"/>
</treenode>
</TREENODES>

 The XML root element must be upper case and named <TREENODES> for the bind to work. If your XML will be coming from a source where you cannot control the root name and structure, an XLS sheet can be used to translate your formatting. The following error will be produced if the correct root is not used.

 

  TreeView
 

 

Create the following aspx file and place it in the same directory as your XML file:

<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %> <%@ Page Language="vb" %>
<HTML>
<HEAD>
<title>XMLIn</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<iewc:TreeView id="TreeView1" runat="server TreeNodeSrc="XMLFile1.xml">
</iewc:TreeView>
</form>
</body>
</HTML>

These two files will produce the same structure we saw in our fist example.

TreeView

The only difference from our first example is the TreeNodeSrc="XMLFile1.xml" attribute.

 

 

Continue to Next Page

 

Page 1, Page 2, Page 3, Page 4, Page 5

Download / Print Complete PDF

 

    Contact Us   Free Extras   Site Map