Database Table
========================================================== ======
Int key int nvarchar (100) nvarchar (100) nvarchar (100) nvarchar (100)
Node_id parent_id node_name address image_url select_image_url
1 0 node_1 http: // **. gif *. gif
2 1 node_1_1 http: // **. gif *. gif
3 2 node_1_1_1 http: // **. gif *. gif
4 0 node_2 http: // **. gif *. gif
5 4 node_2_1 http: // **. gif *. gif
6 5 node_2_1_1 http: // **. gif *. gif
7 0 node_3 http: // ** GIF *. gif
8 7 node_3_1 http: // **. gif *. gif
========================================================== ======
CodeProgram:
========================================================== ======
using system;
using system. collections;
using system. componentmodel;
using system. data;
using system. drawing;
using system. web;
using system. web. sessionstate;
using system. web. ui;
using system. web. UI. webcontrols;
using system. web. UI. htmlcontrols;
using components;
using Microsoft. web. UI. webcontrols;
namespace register
{< br> ///
/// abstract description of webform1.
//
public class webform1: system. web. UI. page
{< br> protected Microsoft. web. UI. webcontrols. treeview tvlist;
private sqlcontrol objsqlcontrol;
private datatable objdatatable;
private void page_load (Object sender, system. eventargs e)
{< br> // place the user code here to initialize the page
If (! Page. ispostback)
{< br> objsqlcontrol = new sqlcontrol ();
treenode node = new treenode ();
objdatatable = objsqlcontrol. selectdata (); // obtain all the data to obtain the datatable
This. createtree (tvlist. nodes, "0"); // create a node
}< BR >}
Private void createtree (treenodecollection node, string parent_id)
{
Dataview dvlist = new dataview (this. objdatatable );
Dvlist. rowfilter = "parent_id = '" + parent_id + "'"; // filter the parent node
Treenode nodetemp;
Foreach (datarowview DV in dvlist)
{
Nodetemp = new treenode ();
Nodetemp. ID = DV ["node_id"]. tostring (); // node ID
Nodetemp. Text = DV ["node_name"]. tostring (); // node name
Nodetemp. navigateurl = DV ["Address"]. tostring (); // node link address
Nodetemp. imageurl = DV ["image"]. tostring (); // node image (not expanded)
Nodetemp. selectedimageurl = DV ["image_ex"]. tostring (); // node image (expand)
Nodetemp. Target = "_ parent"; // node Link Target
Node. Add (nodetemp); // Add a node
This. createtree (nodetemp. nodes, nodetemp. ID); // Recursion
}
}
========================================================== ==========