/// <summary>
/// 绑定TreeView /// </summary> public void BindTreeView() { BLL.GroupBLL GroupBll = new BLL.GroupBLL(); DataTable GroupTable = GroupBll.GetGroup(); //先绑定根节点 for (int i = 0; i < GroupTable.Rows.Count; i++) { TreeNode NoteFather = new TreeNode(GroupTable.Rows[i]["Group"].ToString()); this.TV_Power.Nodes.Add(NoteFather); this.TV_Power.Nodes[i].Value = GroupTable.Rows[i]["ID"].ToString(); BLL.UserBLL UserBll=new BLL.UserBLL (); DataTable UserTable = UserBll.GetAllUser(Convert.ToInt32(GroupTable.Rows[i]["ID"])); //再绑定子节点 for (int j = 0; j < UserTable.Rows.Count; j++) { TreeNode NoteChild = new TreeNode(UserTable.Rows[j]["Name"].ToString()); this.TV_Power.Nodes[i].ChildNodes.Add(NoteChild); this.TV_Power.Nodes[i].ChildNodes[j].ShowCheckBox = true; this.TV_Power.Nodes[i].ChildNodes[j].Value = UserTable.Rows[j]["ID"].ToString(); } } } StringBuilder Power = new StringBuilder(); /// <summary> /// 读取TreeView节点的Value /// </summary> /// <param name="nodes"></param> /// <returns></returns> public string GetTreeViewValue(TreeNodeCollection nodes) { foreach (TreeNode tn in nodes) { if (tn.Checked && tn.ChildNodes.Count == 0) { Power.Append(tn.Value + ","); } GetTreeViewValue(tn.ChildNodes); } return Power.ToString(); }