Get the App
SLTechnology News&Howtos  ›  Development  › 

How to Recursively Loop Child nodes to generate Tree menu in asp.net

Shulou Source: shulou.com Published: 2022-06-03 19:15:23 11月12日 Update

This article is about how TreeView recursively loops through child nodes to generate tree menus in asp.net. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows:

Here, recursive loops are mainly used to obtain child nodes.

/ / generate root node / protected void BindTreeView (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(); 主键 rootnode.Expanded = true; rootnode.Selected = false; rootnode.SelectAction = TreeNodeSelectAction.None; treeview.Nodes.Add(rootnode); CreateChildNode(rootnode, dt); // }}/// /// 生成子节点/// /// /// 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 = "" + rowlist [I] ["node_name"] .ToString () + "; 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}} Thank you for reading! This is the end of the article on "how to recursively loop child nodes to generate tree menu in asp.net". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Nodes recursion generation trees rings menus content more articles good practical articles see knowledge nodes references help loops related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft vpn Shulou Technology Shulou Tech Info MariaDB