如题

解决方案 »

  1.   

    先取出第一级目录数据,即所有的省级行政单位,循环绑定到treenode然后根据父节点的value取出下面市的数据,绑定到该节点下,两个方法就搞定了treeview的绑定实在是个简单东西,连这个都不愿意自己去钻研和尝试一下,还怎么学好ASP.NET>?
      

  2.   

    批评得很好。我是不能显示treeview控件,显示的是文本,请留意是.net 2005.  .net 2005自带了一个treeview(System.Web.UI.WebControls)但是没有GetNodeFromIndex方法。用Microsoft.Web.UI.WebControls下的显示不正常,我装了IEWebControls.exe
      

  3.   


     那更要挨批了,.NET2005下的treeview方法都差不多,更容易循环指定了每个treenode节点的Text属性就能显示出来了等你实现了我想你应该会感到羞愧的..看看这个帖子把 http://topic.csdn.net/u/20080504/14/50dd2578-0850-4f68-8053-a6ab79f26351.html?seed=902170456我在另外一个帖子有回答,中间有搂主贴的绑定代码
      

  4.   

    protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TreeNode nd = new TreeNode();
                nd.Value = "0001"; //存放节点 ID
                nd.Text = "中国";   //设置节点名称
                TreeView1.Nodes.Add(nd);              //添加子节点            this.PopulateNodes(TreeView1.Nodes[0].ChildNodes,"0001");
            }         
        }    private void PopulateNodes(System.Web.UI.WebControls.TreeNodeCollection theNode,string  parentID)
        {
            DataTable dt =  this.getDataTable();
            DataRow[] rows = dt.Select("ParentGovernmentID=" + parentID); //筛选出属于父节点 “node”的子节点集合
                    
            foreach (DataRow dr in rows) //循环子节点集合
            {
                TreeNode nd = new TreeNode();         
                nd.Value = dr["GovernmentID"].ToString(); //存放节点 ID                     
                            
                nd.Text = dr["GovernmentName"].ToString();   //设置节点名称
                this.AddNodes(dt, nd, nd.Value);    //递归,添加该节点的子节点            //if (theNode == null || parentID == "0001")
                if (theNode == null )
                {
                    this.TreeView1.Nodes.Add(nd);    //添加至根节点
                }
                else
                {
                    theNode.Add(nd);              //添加子节点
                }
            }
        }    private void AddNodes(DataTable dt, TreeNode node, string id)
        {
            DataRow[] rows = dt.Select("ParentGovernmentID=" + id); //筛选出属于父节点 “node”的子节点集合
            
            foreach (DataRow dr in rows) //循环子节点集合
            {
                TreeNode nd = new TreeNode();
                //nd.NavigateUrl = dr["URL"].ToString(); //设置浏览的网址
                nd.Value = dr["GovernmentID"].ToString(); //存放节点 ID
                nd.Text = dr["GovernmentName"].ToString();   //设置节点名称
                this.AddNodes(dt, nd, nd.Value);    //递归,添加该节点的子节点            //if (node == null || id == "0001")
                if (node == null)
                {
                    this.TreeView1.Nodes.Add(nd);    //添加至根节点
                }
                else
                {
                    node.ChildNodes.Add(nd);              //添加子节点
                }
            }
        }    private DataTable getDataTable()
        {
            DbConn dbconn = new DbConn();
            string ConnectionString = dbconn.GetConnPara();
            this.Hid_ConnectionString.Value = ConnectionString;
            SqlConnection conn = new SqlConnection(ConnectionString);
            SqlDataAdapter MyAdapter = new SqlDataAdapter();
            SqlCommand comm = new SqlCommand();        //选择DMSupplier中的记录
            comm.CommandText = "select GovernmentID,ParentGovernmentID,GovernmentName from TblGovernment where GovernmentID != '0001' and GovernmentID != '01' order by GovernmentID";
            //comm.CommandText = "select GovernmentID,ParentGovernmentID,GovernmentName from TblGovernment where GovernmentID != '0001' order by GovernmentID";
            comm.Connection = conn;
            MyAdapter.SelectCommand = comm;        DataSet ds = new DataSet();
            MyAdapter.Fill(ds, "TblGovernment");
            return ds.Tables["TblGovernment"];
        }
    表结构GovernmentID         nvarchar 100
    GovernmentName       nvarchar 100
    ParentGovernmentID   nvarchar 100
    为什么只邦定了北京及其下属区域,其他省份的只邦定了省份。请高人回答 。
      

  5.   

    GovernmentID    GovernmentName    ParentGovernmentID
    0001             中国                0000
    11               北京                0001
    1101             北京市辖            11
    110101           海淀                1101
    ...12               天津               0001