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 ;}}}}