jQuery check/uncheck all Checkboxes in ASP.NET

For some odd reason, ASP.NET GridView wraps html elements in a span element. When you apply a CssClass to the asp:CheckBox for instance, you will have a span with that class and inside you’ll have an input with type=checkbox.

So how do you access all of the checkboxes?

$('.chkAllSelector > input:checkbox').click(function() {
         $('.chkRowSelector > input:checkbox').each(
                 this.checked = $('.chkAllSelector > input:checkbox').attr('checked');
     $('.chkRowSelector > input:checkbox').click(function() {
     if ($('.chkAllSelector > input:checkbox').is(':checked') && !($(this).is(':checked')))
          { $('.chkAllSelector > input:checkbox').removeAttr('checked'); }

Related Articles