ASP. NET TreeView dynamically bound database display

Source: Internet
Author: User

The following is a Treeview code dynamically bound to a layer-3 deep tree. For details, see the following website:

Click Open Link

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 product Type = new ProductType (); Product 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 ");} prote Cted void Page_Load (object sender, EventArgs e) {}// Level 1 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 ;}}// the 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 ;}}// the third node void PopulateProducts (TreeNode node) {DataTable dt = new DataTable (); QueryParam queryparam = new QueryParam (); queryparam. add ("ProductTypeItemID", QueryParam. RELATION. EQ, "" + node. V Alue + ""); 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 ;}}}}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.