TreeView绑定无限层级关系类_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > TreeView绑定无限层级关系类

TreeView绑定无限层级关系类

 2014/4/16 19:27:33  随风飞_随风停  博客园  我要评论(0)
  • 摘要:protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){Bind_TV(TreeView1.Nodes);}}#region添加父节点//////添加父节点//////privatevoidBind_TV(TreeNodeCollectiontree){//先添加第一级父节点uintid=Convert.ToUInt32(Session["ID"])
  • 标签:view 关系
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind_TV(TreeView1.Nodes); } } #region 添加父节点 /// /// 添加父节点 /// /// private void Bind_TV(TreeNodeCollection tree) { //先添加第一级父节点 uint id = Convert.ToUInt32(Session["ID"]);//登陆人id string sqlmcount = "select * from account where status=1 and id='" + id + "'"; DataTable Trdtmcount = MySqlDbHelper.GetDataTable(sqlmcount, null); if (Trdtmcount.Rows.Count > 0) { TreeNode tn = new TreeNode(); tn.Value = Trdtmcount.Rows[0]["id"].ToString(); tn.Text = Trdtmcount.Rows[0]["nickname"].ToString(); tree.Add(tn); BindSon(Convert.ToUInt32(Trdtmcount.Rows[0]["id"]), tn.ChildNodes);//根据父节点添加子节点 } } #endregion   #region 递归添加子节点 /// /// 递归添加子节点 /// /// /// private void BindSon(uint fatherid, TreeNodeCollection tree) { string sqlMancount = "select id,nickname from account where masterid=" + fatherid + ";"; DataTable sonDT = MySqlDbHelper.GetDataTable(sqlMancount, null);   DataView dv = new DataView(sonDT); foreach (DataRowView item in dv) { //判断此人id 是否有下属 if (sonDT.Rows.Count > 0)//有 { TreeNode sontn = new TreeNode(); sontn.Value = item["id"].ToString(); sontn.Text = item["nickname"].ToString(); tree.Add(sontn); BindSon(Convert.ToUInt32(item["id"]), sontn.ChildNodes); } } } #endregion
发表评论
用户名: 匿名