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. how to select/deselect all checkboxes in grid?

how to select/deselect all checkboxes in grid?

Scheduled Pinned Locked Moved ASP.NET
javascriptcssdatabasetutorialquestion
6 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.
  • B Offline
    B Offline
    balaji t
    wrote on last edited by
    #1

    hi all, I have a grid which contains checkboxes(similar to mail inbox).I have one href control outside the grid.When i click all the chekboxes inside the grid must b selected.When i click again they should b deselected.Can any1 tell me how to accomplish this using client side code?(i mean in javascript) i wrote a code like this var isChecked = false; function check() { isChecked = !isChecked; var checkboxes = document.getElementsByTagName("INPUT"); var index; for(index = 0; index < checkboxes.length; index++) { if(isChecked) checkboxes[index].checked = true; else checkboxes[index].checked = false; } } Check/Uncheck All The above code is working 5n if the page has no other select controls(radiobutton,checkbox,listbox)outside the grid. But i have one radiobutton control in my page.So when i click the href all the checkboxes inside the grid gets checked but the radiobutton also gets checked.That shoud not happen.How 2 accomplish this?

    T.Balaji

    A B J 3 Replies Last reply
    0
    • B balaji t

      hi all, I have a grid which contains checkboxes(similar to mail inbox).I have one href control outside the grid.When i click all the chekboxes inside the grid must b selected.When i click again they should b deselected.Can any1 tell me how to accomplish this using client side code?(i mean in javascript) i wrote a code like this var isChecked = false; function check() { isChecked = !isChecked; var checkboxes = document.getElementsByTagName("INPUT"); var index; for(index = 0; index < checkboxes.length; index++) { if(isChecked) checkboxes[index].checked = true; else checkboxes[index].checked = false; } } Check/Uncheck All The above code is working 5n if the page has no other select controls(radiobutton,checkbox,listbox)outside the grid. But i have one radiobutton control in my page.So when i click the href all the checkboxes inside the grid gets checked but the radiobutton also gets checked.That shoud not happen.How 2 accomplish this?

      T.Balaji

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Check It Selecting/DeSelecting CheckBox inside Gridview by Samir in Codeproject[^]

      cheers, Abhijit

      B 1 Reply Last reply
      0
      • B balaji t

        hi all, I have a grid which contains checkboxes(similar to mail inbox).I have one href control outside the grid.When i click all the chekboxes inside the grid must b selected.When i click again they should b deselected.Can any1 tell me how to accomplish this using client side code?(i mean in javascript) i wrote a code like this var isChecked = false; function check() { isChecked = !isChecked; var checkboxes = document.getElementsByTagName("INPUT"); var index; for(index = 0; index < checkboxes.length; index++) { if(isChecked) checkboxes[index].checked = true; else checkboxes[index].checked = false; } } Check/Uncheck All The above code is working 5n if the page has no other select controls(radiobutton,checkbox,listbox)outside the grid. But i have one radiobutton control in my page.So when i click the href all the checkboxes inside the grid gets checked but the radiobutton also gets checked.That shoud not happen.How 2 accomplish this?

        T.Balaji

        B Offline
        B Offline
        balaji t
        wrote on last edited by
        #3

        hi abijit, thats fantastic.but my requirment is when the href is clicked this should occur and moreover href is NOT inside the grid.kindly go thru my code.Is it possible to make any check that checkboxes are inside the grid and continue ,like var isChecked = false; function check() { isChecked = !isChecked; var checkboxes = document.getElementsByTagName("INPUT"); //HERE I WANT TO CHECK CONDITION LIKE if(document.getElementbyid("ct100_gvclust1")=="ct100_gvclust1") // AND CONTINUE var index; for(index = 0; index <checkboxes.length;>{ if(isChecked) checkboxes[index].checked = true; else checkboxes[index].checked = false; } }

        T.Balaji

        1 Reply Last reply
        0
        • A Abhijit Jana

          Check It Selecting/DeSelecting CheckBox inside Gridview by Samir in Codeproject[^]

          cheers, Abhijit

          B Offline
          B Offline
          balaji t
          wrote on last edited by
          #4

          hi abhijit, i made the necessary changes and i got it..its working 5n now.thanx

          T.Balaji

          A 1 Reply Last reply
          0
          • B balaji t

            hi all, I have a grid which contains checkboxes(similar to mail inbox).I have one href control outside the grid.When i click all the chekboxes inside the grid must b selected.When i click again they should b deselected.Can any1 tell me how to accomplish this using client side code?(i mean in javascript) i wrote a code like this var isChecked = false; function check() { isChecked = !isChecked; var checkboxes = document.getElementsByTagName("INPUT"); var index; for(index = 0; index < checkboxes.length; index++) { if(isChecked) checkboxes[index].checked = true; else checkboxes[index].checked = false; } } Check/Uncheck All The above code is working 5n if the page has no other select controls(radiobutton,checkbox,listbox)outside the grid. But i have one radiobutton control in my page.So when i click the href all the checkboxes inside the grid gets checked but the radiobutton also gets checked.That shoud not happen.How 2 accomplish this?

            T.Balaji

            J Offline
            J Offline
            janakinandhu
            wrote on last edited by
            #5

            Your tag <a onclick="return check_uncheck1(this );" id="Check" runat="server" href="#">check</a> and Javascript function is as like this function check_uncheck1(Val) { var ValChecked = Val.checked; var ValId = Val.id; var frm = document.forms[0]; // Loop through all elements for (i = 0; i < frm.length; i++) { if(frm.elements[i].checked == true) { frm.elements[i].checked=false; } else { frm.elements[i].checked=true; } } }

            1 Reply Last reply
            0
            • B balaji t

              hi abhijit, i made the necessary changes and i got it..its working 5n now.thanx

              T.Balaji

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              Good !!!

              cheers, Abhijit

              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