|
楼主 |
发表于 2021-3-9 18:15:02
|
显示全部楼层
private void BindTree()
{
YCSD.BLL.Account_Project bll = new YCSD.BLL.Account_Project();
DataTable dt = bll.GetList(10,1,"FatherNode = '-1'").Tables[0];
TreeNode myTreeNode;
for(int i = 0;i<dt.Rows.Count;i++)
{
myTreeNode = new TreeNode();
myTreeNode.Value = dt.Rows[i]["ProjectID"].ToString();
myTreeNode.Text = dt.Rows[i]["ProjectID"].ToString()+dt.Rows[i]["ProjectName"].ToString();
myTreeNode.PopulateOnDemand = true;
TreeView1.Nodes.Add(myTreeNode);
}
}
protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
TreeNode newNode;
YCSD.BLL.Account_Project bll = new YCSD.BLL.Account_Project();
DataTable dt = bll.GetList(10, 1, "FatherNode = '" + e.Node.Value + "'").Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
newNode = new TreeNode();
newNode.Value = dt.Rows[i]["ProjectID"].ToString();
newNode.Text = dt.Rows[i]["ProjectID"].ToString() + dt.Rows[i]["ProjectName"].ToString();
//设置PopulateOnDemand为true,确保下面的子节点仍然可以动态生成。
newNode.PopulateOnDemand = true;
e.Node.ChildNodes.Add(newNode);
}
}
这是两个方法:对英文和数字,来说没有问题,如果是中文就出现问题了 |
|