你用一个TAG字段来表示数据的层次关系就可以了啊

解决方案 »

  1.   

    参见此文
    http://blog.csdn.net/knight94/archive/2006/05/01/704281.aspx
    Http://blog.csdn.net/knight94/archive/2006/03/24/637699.aspx
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
        {
            TreeView tv = new TreeView();
            TreeNode tn = new TreeNode();
            tn.Text = "选择局所";
            tn.NavigateUrl = "1.htm";
            tn.Target = "right";
            TreeNodeInit(0, tn);
            tv.Nodes.Add(tn);
            TreeView1.Nodes.Add(tn);
                  
        }
        #region 递归生成书结点
        private void TreeNodeInit(int upID, System.Web.UI.WebControls.TreeNode tNode)
        {
            SqlConnection SqlConn = new SqlConnection();
            SqlConn.ConnectionString = "Data Source=ip地址;Initial Catalog=***;Persist Security Info=True;User ID=***;password=***;Max Pool Size=512";
            SqlConn.Open();
            SqlCommand SqlCom = new SqlCommand();
            SqlCom.Connection = SqlConn;
            SqlCom.CommandText = "select ibranchno,ibranchname,iupbranchno from jifen.dbo.t_branch where iupbranchno = " + upID + " and IsEnable = 0";
            SqlDataAdapter SqlDaA = new SqlDataAdapter();
            SqlDaA.SelectCommand = SqlCom;
            DataSet ds = new DataSet();
            SqlDaA.Fill(ds);
            //if (ds.Tables[0].Rows.Count < 1)
            //{
            //    TreeNode tNodeTmp = new TreeNode();
            //    tNodeTmp.Text = "生成树失败";
            //    tNode.ChildNodes.Add(tNodeTmp);
            //    return;
            //}
            foreach (System.Data.DataRow myRow in ds.Tables[0].Rows)
            {
                TreeNode tNodeTmp = new TreeNode();
                tNodeTmp.Text = myRow["ibranchname"].ToString();
                tNodeTmp.Value = myRow["ibranchno"].ToString();
                tNodeTmp.NavigateUrl = "operbranch.aspx?ibranchno=" + myRow["ibranchno"].ToString().Trim() + "";
                tNodeTmp.Target = "right";
                tNode.ChildNodes.Add(tNodeTmp);
                TreeNodeInit(int.Parse(myRow["ibranchno"].ToString().Trim()), tNodeTmp);
            }
        }
        #endregion