码迷,mamicode.com
首页 > Web开发 > 详细

WebForm中TreeView的使用

时间:2016-12-07 23:07:03      阅读:407      评论:0      收藏:0      [点我收藏+]

标签:view   treenode   ted   prot   add   lda   bin   page   TreeView   

protected void Page_Load(object sender, EventArgs e)
        {
            DatabaseBind();
            TreeView1.ShowLines = true;
            TreeView1.ExpandDepth = 1;
        }

        public void DatabaseBind()
        {
            string connName = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
            SqlConnection conn = new SqlConnection(connName);
            string sql = "select * from Employees";
            SqlDataAdapter sda =new SqlDataAdapter (sql, conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "Employees");

            TreeNode tree1 = new TreeNode("雇员信息");
            TreeView1.Nodes.Add(tree1);

            for (int i = 0; i < ds.Tables["Employees"].Rows.Count; i++)
            {
                TreeNode tree2 = new TreeNode(ds.Tables["Employees"].Rows[i][1].ToString(),
                                              ds.Tables["Employees"].Rows[1][1].ToString());
                tree1.ChildNodes.Add(tree2);
                for (int j = 0; j <ds.Tables["Employees"].Columns.Count ; j++)
                {
                    TreeNode tree3 = new TreeNode(ds.Tables["Employees"].Rows[i][j].ToString(),
                                              ds.Tables["Employees"].Rows[i][j].ToString());
                tree2.ChildNodes.Add(tree3);
                }

            }
        }

WebForm中TreeView的使用

标签:view   treenode   ted   prot   add   lda   bin   page   TreeView   

原文地址:http://www.cnblogs.com/jiaohuifeng/p/6142864.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!