zoukankan      html  css  js  c++  java
  • TreeView的绑定与读取

    /// <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();
            }

  • 相关阅读:
    Mybatis学习(3)实现数据的增删改查
    Mybatis学习(2)以接口的方式编程
    Mybatis学习(1)开发环境搭建
    Apache Commons 工具类介绍及简单使用
    JAVA枚举使用详解
    Spring中的<context:annotation-config/>配置
    SpringMVC(12)完结篇 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
    SpringMVC(11)表单标签
    面试题
    开发辅助网址
  • 原文地址:https://www.cnblogs.com/huyueping/p/3361449.html
Copyright © 2011-2022 走看看