有关TreeView的应用

这个是一个循环树,下面给你我写的实例:
for (int i = 0; i < dsdoc.Tables[0].Rows.Count; i++)//找出所有父节点
                        {
                            TreeNode node = new TreeNode();
                            node.Text = dsdoc.Tables[0].Rows[i]["teamname"].ToString();
                            node.Value = dsdoc.Tables[0].Rows[i]["teamid"].ToString();
                            node.ImageUrl = Config.teamPic;
                            treenode(node);   //调用循环查找的方法
                            TreeView1.Nodes.Add(node);
                        }

public void treenode(TreeNode parnetnode)//循环遍历viewcity的子节点
    {
        string teamid = parnetnode.Value;
        DataSet ds = Docment.getdoc(teamid);
        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                TreeNode childnode = new TreeNode();
                childnode.Text = ds.Tables[0].Rows[i]["docname"].ToString();
                childnode.Value = ds.Tables[0].Rows[i]["id"].ToString();
                childnode.ImageUrl = Config.docPic;
                parnetnode.ChildNodes.Add(childnode);
            }
        }
        else
        {
            return;
        }
    }
看不懂再问
阅读更多

没有更多推荐了,返回首页