// ************************************************* *** //
<% @ Page language = "c #" codebehind = "Webform1.aspx.cs" autoeventwireup = "false" inherits = "tretest.webform1"%> <% @ register tagprefix = "@ register tagprefix =" IEWC "Namespace =" Microsoft.Web.ui. WebControls "Assembly =" Microsoft.Web.ui.WebControls "%>
// ********************************************************** ******* //
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 system.data.oledb; using microsoft.web.ui.webControls; Namespace Treetest {///
private void AddTestNodes (TreeNode node) {TreeNode testnode = new TreeNode (); testnode.Text = "unfolding ...."; testnode.NodeData = "testnode"; node.Nodes.Add (testnode);} private void AddNodes (TREENODE NODE) {String ParentId = "0"; if (node.parent! = Null) {ParentId = node.nodedata;} // DeepTree is a table name string cmdstr = "SELECT * from DeepTree WHERE PARENTID =" ParentID;
OleDbCommand cmd = new OleDbCommand (cmdstr, Con); try {Con.Open (); OleDbDataReader reader = cmd.ExecuteReader (); while (reader.Read ()) {TreeNode childNode = new TreeNode (); childNode.Text = reader ["content"]. TOSTRING (); childnode.nodedata = reader ["id"]. TOSTRING ();
// ***************** Judging whether there is a child node *********** / / / / DeepTree as a table name
cmdstr = "select count (*) from deeptree where parentid =" childNode.NodeData; OleDbConnection Con1 = new OleDbConnection (dataConStr); OleDbCommand cmd1 = new OleDbCommand (cmdstr, Con1); Con1.Open (); OleDbDataReader reader1 = cmd1. ExecuteReader (); if (Reader1.Read ()) {IF (System.Convert.Toint32 (Reader1 [0])> 0) {addTestNodes (childNode); // If there is a child node, add test node}}}} Reader1. CLOSE (); con1.close ();
// ******************************************************** * //
Node.nodes.add (childNode);}} catch (exception ex) {label3.text = ex.Message;} finally {if (con.state! = connectionState.closed) Con. closed ();
}
#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///
} #Endregion
private void TreeView1_Expand (object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e) {Label1.Text = e.Node; TreeNode node = new TreeNode (); node = TreeView1.GetNodeFromIndex (e.Node); // node = TreeView1.GetNodeFromindex ("0.2"); if (node! = Null) {label2.text = node.nodedata; // Determine the number of subpost sessions under the node, if 1 and for testnode explains unfilled So child node IF ((Node .Nodes.count == 1) && (node.nodes [0] .nodedata == "testnode")) {node.nodes.clear (); // Empty AddNodes (Node); // Fill child node}}} }
Set fields in the database ID, Content, ParentID
PS: Disadvantages, because autopostback is true, each time it is submitted to the server, and the more slower loaded data .. No ASP is fast.