In ASP.NET 2.0, it is necessary to dynamically remove the content from the database, and the dynamic increase node is not difficult. For example, as an example of SQL Server 2000, it is necessary to take the author, take out the author, and be a root node , Then take out what books for each author, as a sub-node, so
<% @ Page language = "c #"%>
<% @ Import namespace = "system.data"%>
<% @ Import namespace = "system.data.sqlclient"%>
<% @ Import namespace = "system.configuration"%>
http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd ">
Void Node_Populate (Object Sender,
System.Web.ui.WebControls.TreenodeEventArgs E)
{
IF (e.node.childnodes.count == 0)
{
Switch (e.node.depth)
{
Case 0:
Fillauthors (E.NODE);
Break;
Case 1:
FillTitlesForauthors (E.NODE);
Break;
}
}
}
Void Fillauthors (Treenode Node)
{
String connString = system.configuration.configurationSettings.
Connectionstrings ["NorthwindConnnection"]. Connectionstring;
SqlConnection Connection = New SqlConnection (Conntring);
Sqlcommand command = new sqlcommand ("SELECT * FROM
Authors ", Connection);
SqlDataAdapter Adapter = New SqldataAdapter (Command);
Dataset authors = new dataset ();
Adapter.Fill (Authors);
IF (authors.tables.count> 0)
{
Foreach (DataRow Row In Authors.tables [0] .rows)
{
Treenode NewNode = New
Treenode (Row ["AU_FNAME"]. TOSTRING () ""
Row ["AU_LNAME"]. TOSTRING (),
Row ["AU_ID"]. TOSTRING ());
Newnode.populateOndemand = true; newnode.seectivity = Treenodeeelectrically.expand;
Node.childNodes.Add (newNode);
}
}
}
Void FillTitlesForauthors (Treenode Node)
{
String authorid = node.value;
String connString = system.configuration.configurationSettings.
Connectionstrings ["NorthwindConnnection"]. Connectionstring;
SqlConnection Connection = New SqlConnection (Conntring);
Sqlcommand command = new sqlcommand ("SELECT T.TITLE,
T.TITLE_ID from Titles T "
"Inner Join Titleauthor Ta On
T.TITLE_ID = TA.TITLE_ID "
"Where ta.au_id = '" authorid "'", connection);
SqlDataAdapter Adapter = New SqldataAdapter (Command);
DataSet TitlesForauthors = New DataSet ();
Adapter.Fill (TitlesForauthors);
IF (titlesforauthors.tables.count> 0)
{
Foreach (Datarow Row In TitlesForauthors.tables [0] .rows)
{
Treenode NewNode = New Treenode
Row ["Title"]. TOSTRING (), ROW ["Title_ID"]. TOSTRING ());
NewNode.PopulateOndemand = false;
NewNode.Selectivity = Treenodeseelectrics .NONE;
Node.childNodes.Add (newNode);
}
}
}
script>
hEAD>