1. recursive functions
// 'Recursively traverse the self-built directory tree ================================== ========================================================== =====
Private void showdir (string szml, string sindex)
{
System. Data. sqlclient. sqlconnection sqlcon = new system. Data. sqlclient. sqlconnection (connectionstring );
String sqlstr = "select * From mltable where mlzml = N'" + szml + "'";
System. Data. sqlclient. sqldataadapter sqlada = new system. Data. sqlclient. sqldataadapter (sqlstr, sqlcon );
System. Data. datatable dt = new datatable ();
Sqlada. Fill (DT );
Microsoft. Web. UI. webcontrols. treenode node1;
String sindex0;
String sindex2;
Int theid;
Int sindex1 = 0; // The last value of the record tree
Foreach (system. Data. datarow dtdatarow in DT. Rows)
{
Theid = convert. toint32 (dtdatarow ["mlid"]);
Node1 = new Microsoft. Web. UI. webcontrols. treenode ();
Node1.text = dtdatarow ["mlmc"]. tostring ();
Node1.imageurl = "images/trees/folder.gif ";
Node1.expandedimageurl = "images/trees/folderopen.gif ";
Node1.expanded = false;
Node1.navigateurl = "admin_tree_show.aspx? Theid = "+ theid +" & sindex = "+ sindex +". "+ sindex1.tostring ();
Node1.id = "";
Node1.target = "Main ";
If (sindex = "")
{
Sindex2 = treeview1.nodes. indexof (node1). tostring ();
Sindex0 = sindex2;
}
Else
{
Microsoft. Web. UI. webcontrols. treenode pnode = treeview1.getnodefromindex (sindex );
Pnode. nodes. Add (node1 );
Sindex2 = pnode. nodes. indexof (node1). tostring ();
Sindex0 = sindex + "." + sindex2;
Sindex1 ++; // record the number of leaves under the current tree, that is, the number of current leaves
}
Showdir (dtdatarow ["mlid"]. tostring (), sindex0 );
}
Sqlcon. Close ();
}