Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. tree view select all child nodes when to click parent nodes

tree view select all child nodes when to click parent nodes

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-netdata-structures
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T_Teef
    wrote on last edited by
    #1

    I have tree view control on my asp.net web page. this tree control has check boxes on every node. I want when user selects or make parent node check box checked then its child should also get checked automatically. how can i do this ? kindly its urgent, plz send some code hints.

    T 1 Reply Last reply
    0
    • T T_Teef

      I have tree view control on my asp.net web page. this tree control has check boxes on every node. I want when user selects or make parent node check box checked then its child should also get checked automatically. how can i do this ? kindly its urgent, plz send some code hints.

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      Write some fancy javascript to update all the sub nodes that contain a checkbox, or put the treeview in an ajax panel and use server side code to check all the checkboxes.

      I didn't get any requirements for the signature

      T 1 Reply Last reply
      0
      • T ToddHileHoffer

        Write some fancy javascript to update all the sub nodes that contain a checkbox, or put the treeview in an ajax panel and use server side code to check all the checkboxes.

        I didn't get any requirements for the signature

        T Offline
        T Offline
        T_Teef
        wrote on last edited by
        #3

        we r using asp.net and we have also created check boxes, we want parent node check box checked then its child should also get checked automatically.

        F 1 Reply Last reply
        0
        • T T_Teef

          we r using asp.net and we have also created check boxes, we want parent node check box checked then its child should also get checked automatically.

          F Offline
          F Offline
          Fayu
          wrote on last edited by
          #4

          enumerate though the childnodes and check the checkboxes. Post your code so you can get further help.

          T 1 Reply Last reply
          0
          • F Fayu

            enumerate though the childnodes and check the checkboxes. Post your code so you can get further help.

            T Offline
            T Offline
            T_Teef
            wrote on last edited by
            #5

            heres the code

            public partial class _Default : System.Web.UI.Page
            {
            public static SqlConnection sqlConn = new SqlConnection();
            public static SqlCommand sqlCmmd = new SqlCommand();
            public static SqlDataAdapter sqlDAptr = new SqlDataAdapter();
            //public DataSet busDataSet
            //{
            // get
            // {
            // return DS;
            // }
            // set
            // {
            // DS = value;
            // }
            //}

            protected void Page\_Load(object sender, EventArgs e)
            {
                try
                {
                    //GetTables();
                    PassQuery();
                    //abc();
                }
                catch (Exception)
                {
                    throw;
                }
            }
            
            
            public void PassQuery()
            {
                this.TreeView1.Nodes.Clear();
            
                DataSet myFirstTable = new DataSet();
            
                string Query = "select name from sys.tables";
                myFirstTable = Retun\_Table\_BasedOn\_Query(Query);
                DataSet\[\] mySecondTable = new DataSet\[myFirstTable.Tables\[0\].Rows.Count\];
            
                for (int i = 0; i < myFirstTable.Tables\["Table"\].Rows.Count; i++)
                {
                    string str1 = myFirstTable.Tables\["Table"\].Rows\[i\]\[0\].ToString();
            
                    string Query2 = "SELECT  sysobjects.name As Names, syscolumns.name AS FieldName " +
                                   "FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id " +
                                   "WHERE (sysobjects.name = '" + str1 + "')";
                    mySecondTable\[i\] = Retun\_Table\_BasedOn\_Query(Query2);
                    
                    TreeNode tnParent;
                    TreeNode tnChild;
            
                    for (int a = 0; a < 1; a++)
                    {
                        tnParent = new TreeNode();
                        tnParent.Text = str1.ToString();
                        TreeView1.Nodes.Add(tnParent);
            
                        foreach (DataRow rowChild in mySecondTable\[i\].Tables\["Table"\].Rows)
                        {
                            tnChild = new TreeNode();
                            tnChild.Text  = rowChild\["FieldName"\].ToString();
                            tnParent.ChildNodes.Add(tnChild);
                        }
                    }
                }
            }
            
            public void Open\_Connection()
            {
                string Conn\_Str = "Data Source=dev-test;Initial Catalog=Malik;Persist Security Info=True;User ID=interns;Password=intern123";
                sqlConn = new SqlConnection(Conn\_Str);
                if (sqlConn.State != ConnectionState.Open)
                {
                    sqlConn.Open();
                }
            }
            
            public DataSet Retun\_Table\_BasedOn\_Query(String Quer
            
            T 1 Reply Last reply
            0
            • T T_Teef

              heres the code

              public partial class _Default : System.Web.UI.Page
              {
              public static SqlConnection sqlConn = new SqlConnection();
              public static SqlCommand sqlCmmd = new SqlCommand();
              public static SqlDataAdapter sqlDAptr = new SqlDataAdapter();
              //public DataSet busDataSet
              //{
              // get
              // {
              // return DS;
              // }
              // set
              // {
              // DS = value;
              // }
              //}

              protected void Page\_Load(object sender, EventArgs e)
              {
                  try
                  {
                      //GetTables();
                      PassQuery();
                      //abc();
                  }
                  catch (Exception)
                  {
                      throw;
                  }
              }
              
              
              public void PassQuery()
              {
                  this.TreeView1.Nodes.Clear();
              
                  DataSet myFirstTable = new DataSet();
              
                  string Query = "select name from sys.tables";
                  myFirstTable = Retun\_Table\_BasedOn\_Query(Query);
                  DataSet\[\] mySecondTable = new DataSet\[myFirstTable.Tables\[0\].Rows.Count\];
              
                  for (int i = 0; i < myFirstTable.Tables\["Table"\].Rows.Count; i++)
                  {
                      string str1 = myFirstTable.Tables\["Table"\].Rows\[i\]\[0\].ToString();
              
                      string Query2 = "SELECT  sysobjects.name As Names, syscolumns.name AS FieldName " +
                                     "FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id " +
                                     "WHERE (sysobjects.name = '" + str1 + "')";
                      mySecondTable\[i\] = Retun\_Table\_BasedOn\_Query(Query2);
                      
                      TreeNode tnParent;
                      TreeNode tnChild;
              
                      for (int a = 0; a < 1; a++)
                      {
                          tnParent = new TreeNode();
                          tnParent.Text = str1.ToString();
                          TreeView1.Nodes.Add(tnParent);
              
                          foreach (DataRow rowChild in mySecondTable\[i\].Tables\["Table"\].Rows)
                          {
                              tnChild = new TreeNode();
                              tnChild.Text  = rowChild\["FieldName"\].ToString();
                              tnParent.ChildNodes.Add(tnChild);
                          }
                      }
                  }
              }
              
              public void Open\_Connection()
              {
                  string Conn\_Str = "Data Source=dev-test;Initial Catalog=Malik;Persist Security Info=True;User ID=interns;Password=intern123";
                  sqlConn = new SqlConnection(Conn\_Str);
                  if (sqlConn.State != ConnectionState.Open)
                  {
                      sqlConn.Open();
                  }
              }
              
              public DataSet Retun\_Table\_BasedOn\_Query(String Quer
              
              T Offline
              T Offline
              ToddHileHoffer
              wrote on last edited by
              #6

              T_Teef wrote:

              Open_Connection(); DataSet mydataSet = new DataSet(); sqlCmmd = new SqlCommand(Query, sqlConn); sqlDAptr = new SqlDataAdapter(sqlCmmd); sqlDAptr.Fill(mydataSet); return mydataSet;

              FYI. If you pass an open connection to a SqlDataAdapter it will not close automatically. Check your sql server you probably have a bunch open connections that aren't being closed. Also, where is your code to handle the treeviews click event?

              I didn't get any requirements for the signature

              T 1 Reply Last reply
              0
              • T ToddHileHoffer

                T_Teef wrote:

                Open_Connection(); DataSet mydataSet = new DataSet(); sqlCmmd = new SqlCommand(Query, sqlConn); sqlDAptr = new SqlDataAdapter(sqlCmmd); sqlDAptr.Fill(mydataSet); return mydataSet;

                FYI. If you pass an open connection to a SqlDataAdapter it will not close automatically. Check your sql server you probably have a bunch open connections that aren't being closed. Also, where is your code to handle the treeviews click event?

                I didn't get any requirements for the signature

                T Offline
                T Offline
                T_Teef
                wrote on last edited by
                #7

                thats why we have posted the code to get the help to obtain a piece of code to handle the treeviews click event :zzz:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups