(四)递归绑定值到树
1.数据库中有个树的表,必须有id和pid这两个字段才能构成树
绑定的代码
绑定的代码
public void BoundProductTypeToTree(TreeNodeCollection productTypeTree,string root)
{
foreach(ProductType pt in _productBLl.GetProductTypesByPID(root))
{
TreeNode tn = new TreeNode(pt.name, pt.ID + "," + pt.pid);
productTypeTree.Add(tn);
BoundProductTypeToTree(tn.ChildNodes, pt.ID);
}
}
2.发现树的一个bug,线拼的不准{
foreach(ProductType pt in _productBLl.GetProductTypesByPID(root))
{
TreeNode tn = new TreeNode(pt.name, pt.ID + "," + pt.pid);
productTypeTree.Add(tn);
BoundProductTypeToTree(tn.ChildNodes, pt.ID);
}
}