大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
下面是一个Treeview动态的绑定3层深度的树的代码,有需要的朋友可以参考一下
代码如下:
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)
{
}
//第一级节点(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 ;
}
}
}
//第二级节点
void PopulateProductType(TreeNode node)
{
DataTable dt = new DataTable();
QueryParam queryparam = new QueryParam();
queryparam.Add("ParentID", QueryParam.RELATION.EQ, "" + node.Value + "");
dt = productType.GetListByBranchNode(queryparam);
unity3d http://www.unitymanual.com/
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 ;
}
}
}
//第三个节点
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;
}
}
}
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。