views:

610

answers:

2

Hello, I have a grid view with multiple check box columns and I was wondering if anyone could show me how to select all check boxes in a unique column. I don't want to select a check box in the header and have it select all the check boxes in the grid view. I'm new to jQuery, literally at the beginners stage and was hoping to be able to do it in jquery.

Thanks in Advance, Terry

A: 

all checkbox has to be the class = "myClass"

$(".myClass").attr("checked", true);

Extended example:

<html>
  <head>
    <title></title>
    <script type="text/javascript" src="../jquery-ui-1.7.custom/js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript">
        jQuery(function(){
            alert('before')
            $(".myClass").attr("checked", true);
            alert('after')
        });
    </script>
  </head>
  <body>
      <input type="checkbox" id="cb1" class="myClass" value="false">
      <input type="checkbox" id="cb2" class="myClass" value="false">
      <input type="checkbox" id="cb3" class="myClass" value="false">
      <input type="checkbox" id="cb4" class="myClass" value="false">
      <input type="checkbox" id="cb5" class="myClass" value="false">
      <input type="checkbox" id="cb6" class="myClass" value="false">
      <input type="checkbox" id="cb7" class="myClass" value="false">
      <input type="checkbox" id="cb8" class="myClass" value="false">
      <input type="checkbox" id="cb9" class="myClass" value="false">
      <input type="checkbox" id="cb0" class="myClass" value="false">
  </body>
</html>
andres descalzo
Hi Andre, I tried your solution as well and no luck. I get the same error I posted to Andra below....
TGS
I only have 600 characters to display my html and it goes way over.basically, when the browser reads this line:$(".Bill1").attr("checked", true);The browser gives the following error:Microsoft JScript runtime error: 'null' is null or not an objectall of the checkboxes are in a gridview and all have a class="Bill1" assigned to them. If I use document.getelementbyid I see that the checkboxes exist, but with the jquery using $(document).ready(function() { $(".Bill1").attr("checked", false);});it crashes..why can't jquery see the checkbox?Terry
TGS
How the 600 characters are created? could put the code of checkboxs, to see the html.
andres descalzo
A: 

// assuming you want to specify the column index. var selectedColumnIndex = 2;

$('td:nth-child(' + selectedColumnIndex + ')').each( function(){
   $(":checkbox", $(this)).attr("checked", true);
});
Anwar Chandra
Hi Andra, I tried your solution, but I get the following error in javascript:Microsoft JScript runtime error: 'null' is null or not an object I believe I have to reference the gridview before referencing the columns don't I?
TGS
Hi TGS, show me some your GridView markup. also, please tag asp.net on your question.
Anwar Chandra