BLL.Area bll = new BLL.Area();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.BindTreeViewMenu();
        }        private void BindTreeViewMenu()
        {
            DataRow dr;
            DataSet ds = bll.GetList(" ParentID=1 ");
            int intLen = ds.Tables[0].Rows.Count;
            for (int i = 0; i < intLen; i++)
            {
                TreeNode trnTmp = new TreeNode();
                dr = ds.Tables[0].Rows[i];               
                trnTmp.Text = dr["AreaName"].ToString();
                this.treeArea.Nodes.Add(trnTmp);
            }父ID"ParentID"为1的一级目录都正常显示了,怎么能把每个一级目录下边的子目录显示出来啊?这个.CS文件应该怎么改啊?

解决方案 »

  1.   

    http://blog.csdn.net/taomanman/archive/2009/11/16/4816297.aspx
      

  2.   


        protected void Page_Load(object sender, EventArgs e)
        {
            GetTable();
            Bind_Tree(0, null);
        }
        public void Bind_Tree(int fid,TreeNode node)
        {
            DataTable dt = ViewState["Table"] as DataTable;
            DataRow[] row = dt.Select("fParentid=" + fid + "");
            foreach (DataRow r in row)
            {
                TreeNode n = new TreeNode(r["fname"].ToString(), r["fid"].ToString());
                if (fid == 0)
                    TreeView1.Nodes.Add(n);
                else
                    node.ChildNodes.Add(n);
                Bind_Tree(Convert.ToInt32(r["fid"]), n);
            }
        }
        public void GetTable()
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["daxueConnection"].ConnectionString;
                conn.Open();
                string strSql = "select fid,fname,fParentid from daxue";
                SqlDataAdapter da = new SqlDataAdapter(strSql, conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                ViewState["Table"] = dt;
            }
        }
      

  3.   

    DataSet ds = bll.GetList(" ParentID=1 ");取出的数据是ds 
    请高手按照2楼的看下我的代码应该怎么改啊?
      

  4.   

    根据2楼指点,修改的代码如下,望高手指点有什么不足的地方
         BLL.Area area = new BLL.Area();
            protected void Page_Load(object sender, EventArgs e)
            {
                this.BindTreeView(1,null);
            }        private void BindTreeView(int id,TreeNode node)
            {
                
                string strwhere = string.Format(" ParentID={0} ",id);
                DataSet ds = bll.GetList(strwhere);            
                int intLen = ds.Tables[0].Rows.Count;
                for (int i=0 ; i < intLen; i++)
                {
                    TreeNode n = new TreeNode(ds.Tables[0].Rows[i]["AreaName"].ToString(), ds.Tables[0].Rows[i]["ID"].ToString());
                    if (Convert.ToInt32(ds.Tables[0].Rows[i]["ParentID"].ToString())==1)
                    {
                        this.treeArea.Nodes.Add(n);
                    }
                    else
                    {
                        node.ChildNodes.Add(n);
                    }
                    BindTreeView(Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()), n);
                }
                
            }
      

  5.   

        private void bindTreeView1()
            {
                string sql = "select * from doctype where isdel=0";
                DataTable dt = db.ExecuteDataTable(sql, CommandType.Text, null);
                DataRow[] dr=dt.Select("updirid='-1'");
                for (int i = 0; i < dr.Length; i++)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = dr[i]["docdirname"].ToString();
                    tn.Tag=dr[i]["docdirid"].ToString();
                    if (dr[i]["isdir"].ToString() == "1")
                    {
                        tn.ImageIndex = 0;
                        FillTree(tn, dt);                   
                    }
                    else
                    {
                        tn.ImageIndex = 1;
                    }
                    treeView1.Nodes.Add(tn);
                }
            }        private void FillTree(TreeNode node, DataTable dt)
            {
                DataRow[] dd = dt.Select("updirid='"+node.Tag.ToString()+"'");
                if (dd.Length > 0)
                {
                    for (int i = 0; i < dd.Length; i++)
                    {
                        TreeNode tnn = new TreeNode();
                        tnn.Text = dd[i]["docdirname"].ToString();
                        tnn.Tag = dd[i]["docdirid"].ToString();
                        if (dd[i]["isdir"].ToString() == "1")
                        {
                            tnn.ImageIndex = 0;
                            FillTree(tnn, dt);
                        }
                        else
                        {
                            tnn.ImageIndex = 1;
                        }
                        node.Nodes.Add(tnn);
                    }
                }
            }
      

  6.   

     private void BindTreeView(int id,TreeNode node)
            {
                
                string strwhere = string.Format(" ParentID={0} ",id);
                DataSet ds = bll.GetList(strwhere);            
                int intLen = ds.Tables[0].Rows.Count;
                for (int i=0 ; i < intLen; i++)
                {
                    TreeNode n = new TreeNode(ds.Tables[0].Rows[i]["AreaName"].ToString(), ds.Tables[0].Rows[i]["ID"].ToString());
                    if (Convert.ToInt32(ds.Tables[0].Rows[i]["ParentID"].ToString())==1)
                    {
                        this.treeArea.Nodes.Add(n);
                    }
                    else
                    {
                        node.ChildNodes.Add(n);
                    }
                    BindTreeView(Convert.ToInt32(ds.Tables[0].Rows[i]["ID"].ToString()), n);
                }
                
            }
    你哪个地方在循环访问数据库,,
      

  7.   

    DataSet ds = bll.GetList(strwhere); 这个是根据父ID读取数据库内容,
    请问该怎么调整?
    另外需要对节点进行编辑修改删除 应该怎么改?
      

  8.   


    我5楼的帖子不是写的很清楚吗?
    在现有的数据集datatable里面进行二次查询,,,
      

  9.   

    treenode node=tv.SelectedNode;修改
     node.text=要修改的name;
    删除
    tv.SelectedNode.Remove();  
    id=node.tag.toString();
    记得通过id在数据库中进行修改和删除操作结贴吧