Thursday, August 25, 2016

Check or Uncheck all CheckBoxes in an ASP.NET GridView using jQuery





var $headerCheckBox = $('.headerSelectAll input[type="checkbox"]');
        var $childCheckBox = $('.childSelect input[type="checkbox"]');
        $($headerCheckBox).change(function () {
            $childCheckBox.each(function () {
                this.checked = $headerCheckBox[0].checked;
            })
        });

        $($childCheckBox).change(function () {
            // if any of the checkbox is unchecked
            // check all checkbox should be cleared
            if (!$(this).is(':checked')) {
                $headerCheckBox.removeAttr('checked');
            }
            else {
                // if all of the checkbox is checked
                // check all checkbox should be checked
                if ($childCheckBox.length == $childCheckBox.filter(':checked').length) {
                    $headerCheckBox[0].checked = true;
                }
            }
        });

2 comments:

Sapphire Solutions said...

Very interesting post...

Check or Uncheck all CheckBoxes in an ASP.NET GridView using jQuery

Top Reasons to Know Before you Hire a Dot Net Developers

hire asp.net developers

Sarkari result said...

This information is informational; I am inspired with your post writing style & how continuously you describe this topic.


Sarkari Result

Free job alert