Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use TreeView in ASP.NET

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use TreeView in ASP.NET". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use TreeView in ASP.NET.

The copy code is as follows:

Using System

Using System.Collections

Using System.Configuration

Using System.Data

Using System.Web

Using System.Web.Security

Using System.Web.UI

Using System.Web.UI.HtmlControls

Using System.Web.UI.WebControls

Using System.Web.UI.WebControls.WebParts

Using System.Data.SqlClient

Using Common

Using DataAccess

Public partial class Controls_ProductType2: System.Web.UI.UserControl

{

ProductType productType = new ProductType ()

Product product = new Product ()

Protected void TreeView_TreeNodePopulate (object sender, TreeNodeEventArgs e)

{

If (e.Node.ChildNodes.Count = = 0)

{

Switch (e.Node.Depth)

{

Case 0:

PopulateCategories (e.Node)

Break

Case 1:

PopulateProductType (e.Node)

Break

Case 2:

PopulateProducts (e.Node)

Break

}

}

/ / int I = TreeToXml.TreeToXML (TreeView1, "D:/TreeToXML.xml")

}

Protected void Page_Load (object sender, EventArgs e)

{

}

/ / first-level node (parentID=0)

Void PopulateCategories (TreeNode node)

{

DataTable dt = new DataTable ()

Dt = productType.GetListByFatherNode ()

If (dt.Rows.Count > 0)

{

Foreach (DataRow row in dt.Rows)

{

TreeNode NewNode = new TreeNode (row ["ProductTypeName"] .ToString (), row ["ProductTypeID"] .ToString (), ".. / WebProductList.aspx?productTypeIdOne=" + row ["ProductTypeID"] .ToString () + ",")

NewNode.PopulateOnDemand = true

NewNode.SelectAction = TreeNodeSelectAction.Expand

Node.ChildNodes.Add (NewNode)

Node.Expanded = true

}

}

}

/ / second-level node

Void PopulateProductType (TreeNode node)

{

DataTable dt = new DataTable ()

QueryParam queryparam = new QueryParam ()

Queryparam.Add ("ParentID", QueryParam.RELATION.EQ, "" + node.Value + "")

Dt = productType.GetListByBranchNode (queryparam)

If (dt.Rows.Count > 0)

{

Foreach (DataRow row in dt.Rows)

{

TreeNode NewNode = new TreeNode (row ["ProductTypeName"] .ToString (), row ["ProductTypeID"] .ToString (), ".. / WebProductList.aspx?productTypeIdTwo=" + row ["ProductTypeID"] .ToString () + ",")

NewNode.PopulateOnDemand = true

NewNode.SelectAction = TreeNodeSelectAction.Expand

Node.ChildNodes.Add (NewNode)

Node.Expanded = false

}

}

}

/ / third node

Void PopulateProducts (TreeNode node)

{

DataTable dt = new DataTable ()

QueryParam queryparam = new QueryParam ()

Queryparam.Add ("ProductTypeItemID", QueryParam.RELATION.EQ, "" + node.Value + "")

Dt = product.GetList (queryparam)

If (dt.Rows.Count > 0)

{

Foreach (DataRow row in dt.Rows)

{

TreeNode NewNode = new TreeNode (row ["ProductName"] .ToString (), row ["ProductID"] .ToString (), ".. / WebProductDetaile.aspx?productID=" + row ["ProductID"] .ToString () + ",")

/ / NewNode.PopulateOnDemand = false

/ / NewNode.SelectAction = TreeNodeSelectAction.None

NewNode.PopulateOnDemand = true

NewNode.SelectAction = TreeNodeSelectAction.Expand

Node.ChildNodes.Add (NewNode)

Node.Expanded = false

}

}

}

}

Thank you for reading, the above is the content of "how to use TreeView in ASP.NET", after the study of this article, I believe you have a deeper understanding of how to use TreeView in ASP.NET, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report