This article illustrates the method of generating a tree-shaped menu of asp.net treeview recursive loop child nodes. Share to everyone for your reference, specific as follows:
This mainly uses recursive loops to get the sub nodes.
<summary>///Generate root node///</summary>///<param name= "treeview" ></param> protected void Bindtre
Eview (Long ID, treeview treeview) {DataTable dt = menulogic.getmenu2 (ID, User.Identity.Name); Treeview.
Nodes.clear (); datarow[] ParentRow = dt.
Select ("Par_id=0"); for (int i = 0; i < ParentRow. Length;
i++) {TreeNode RootNode = new TreeNode (); RootNode. Text = parentrow[i]["Node_name"]. ToString (); PARENTROW[I][3].
ToString (); RootNode. Value = parentrow[i]["ID"]. ToString (); PARENTROW[I][1]. ToString (); Primary key RootNode.
Expanded = true; RootNode.
Selected = false; RootNode.
SelectAction = Treenodeselectaction.none; Treeview.
Nodes.Add (RootNode); Createchildnode (rootnode, DT); }///<summary>///Generation sub-node///</summary>///<param name= "parentnode" ></param>///<pa Ram Name= "DataTable" ></param> protected void Createchildnode (TreeNode parentnode, DataTable DataTable) {datarow[] rowlist = DataTable.
Select ("par_id=" + parentnode.value); for (int i = 0; i < rowlist. Length;
i++) {TreeNode node = new TreeNode (); if (DataTable). Select ("par_id=" + rowlist[i]["id"]. ToString (). Trim ()). Length > 0) {node. Text = rowlist[i]["Node_name"].
ToString (); Node. Value = rowlist[i]["ID"].
ToString (); } else {node. Text = "<a href=\" javascript:;\ "onclick=\" OpenURL (' "+ rowlist[i][" url "]. ToString (). Trim () + "', this" > "+ rowlist[i][" Node_name "].
ToString () + "</a>"; Node. Value = rowlist[i]["ID"].
ToString (); node.
Expanded = false; Node.
Selected = false; Node.
SelectAction = Treenodeselectaction.none;
PARENTNODE.CHILDNODES.ADD (node); Createchildnode (node, DataTable);
Recursive call}}
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.