zoukankan      html  css  js  c++  java
  • TreeView控件的使用 Hello

    使用TREEVIEW控件编写的一段代码,想了N久才出来

        protected void TreeView1_Load()
        {
            //用于填充TreeView1
            SqlCommand Mycommand1 = new SqlCommand("select *  from CHAPTER where Course_ID=0", Myconn);
            SqlDataReader DR1 = Mycommand1.ExecuteReader();
            //SqlDataAdapter DA1 = new SqlDataAdapter(Mycommand1);
            //DataSet DS1 = new DataSet("temp");
            //DA1.Fill(DS1);

            SqlCommand Mycommand2;
            SqlDataReader DR2;
           
           
            while(DR1.Read())
            {
                TreeNode NewNode = new TreeNode(DR1["Chapter_Name"].ToString());
                NewNode.Value = DR1["Chapter_ID"].ToString();
                NewNode.Collapse();
                //二层结点--->
                //Mycommand2 = new SqlCommand("select * from SECTION where Chapter_ID="+DR1["Chapter_ID"].ToString(),Myconn);
                //DR2 = Mycommand2.ExecuteReader();
                //TreeNode NewNode2 = new TreeNode(DR2["Section_Name"].ToString());
                //NewNode.ChildNodes.Add(NewNode2);
                //<<-----
               
                TreeView1.Nodes.Add(NewNode);

            }
            DR1.Close();

            foreach (TreeNode NewNode in TreeView1.Nodes)
            {
                Mycommand2 = new SqlCommand("select * from SECTION where Chapter_ID=" + NewNode.Value.ToString(), Myconn);
                DR2 = Mycommand2.ExecuteReader();
                while (DR2.Read())
                {
                    TreeNode TempNode = new TreeNode(DR2["Section_Name"].ToString());
                    TempNode.NavigateUrl = "#";
                    TempNode.Target = "_blank";
                    NewNode.ChildNodes.Add(TempNode);

                }
                DR2.Close();
            }
           

            /*
            if (DS1.Tables["CHAPTER"].Rows.Count.CompareTo(0)>0)
            {
                    foreach (DataRow Row in DS1.Tables["CHAPTER"].Rows)
                    {
                       TreeNode NewNode = new TreeNode(Row["Chapter_Name"].ToString());
                        //二层结点--->
                       Mycommand2 = new SqlCommand("select * from SECTION where Chapter_ID=" + Row["Chapter_Name"].ToString(), Myconn);
                       DR2 = Mycommand2.ExecuteReader();
                       TreeNode NewNode2 = new TreeNode(DR2["Section_Name"].ToString());
                       NewNode.ChildNodes.Add(NewNode2);
                        //<<---------
                       TreeView1.Nodes.Add(NewNode);
                    }
            }
                    DS1.Dispose();
           */
        }

  • 相关阅读:
    ObjectiveC 语言入门教程 | MacCocoa
    Neopythonic memcached cliend
    python Preventing django from appending "_id" to a foreign key field Stack Overflow
    JQuery and python script | python | PyMantra
    Import error on django models.py
    如何成为Python高手 技术讨论 云计算开发者社区 Powered by Discuz!
    [Hadoop] 实际应用场景之 百度 Zhu_Julian's Notes (朱显杰的技术博客) 博客频道 CSDN.NET
    DjangoResources – Django
    hue
    Huseyin Yilmaz
  • 原文地址:https://www.cnblogs.com/zhfen/p/366003.html
Copyright © 2011-2022 走看看