protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindTree();
}
}
private void bindTree()
{
ALIYUN_PIC.BLL.Folder_oper_BLL bll = new Folder_oper_BLL();
DataTable dt = bll.PIC_Bind();//得到需要的datatable
this.FillNode(dt, null);
}
private void FillNode(DataTable dt, TreeNode node)
{
DataView dv = new DataView(dt);
if (node == null) //根结点
{
dv.RowFilter = "PARENT_NODE='0'"; //筛选到根结点的所有子节点
}
else //不是根结点
{
dv.RowFilter = "PARENT_NODE='" + node.Value + "'"; //筛选对应节点的所有子节点
}
foreach (DataRowView drv in dv) //遍历填充节点的所有子节点,如果传入的节点node为叶子节点,遍历要退出,不再进行递归
{
TreeNode no = new TreeNode(drv["NODE_NAME"].ToString(), drv["id"].ToString());
FillNode(dt, no); //填充no节点的子节点
if (node == null)
{
this.PIC_TREE.Nodes.Add(no);
}
else
{
node.ChildNodes.Add(no);
}
}
}