Copy codeThe 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)
{
}
// 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;
}
}
}
// Level 2 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. 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;
}
}
}
}