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 2

Creating a Simple TreeView

Lets start by creating the "Hello World" version of a TreeView. If you are coding by hand, create this new file:

<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %> <%@ Page Language="vb" AutoEventWireup="false" "%>

<HTML>
<HEAD>
<title>Simple Tree</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<iewc:TreeView id="TreeView1" runat="server">
<iewc:TreeNode Text="Parent">
<iewc:TreeNode Text="Child1">
</iewc:TreeNode>
<iewc:TreeNode Text="Child2">
</iewc:TreeNode>
</iewc:TreeNode>
</iewc:TreeView>
</form>
</body>
</HTML>

 

 

For Visual Studio users, drag the TreeView icon on your page. With TreeView selected in the Properties area, click the Nodes (Collection).

TreeView

Next, add a root and two children. Change the text properties for each in the TreeNodeEditor.

TreeView

  This should give you the following Web page display
  TreeView
  Because the TreeView is not part of the .NET Framework, lines one and two import and register the WebControls namespace.
   
  Continue to Next Page
 

 

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

Download / Print Complete PDF

 

    Contact Us   Free Extras   Site Map