Create an Asp.net Gridview with Checkbox in each row
One of the frequent requirements for Asp.net Gridview is to add a checkbox for each row and a checkbox to select all the items like the Gridview below. This can be easily achieved by using jQuery. You can find the complete source code here.
$(document).ready(function () {
$(‘input[name$=”CDSelectAll”]’).click(function () {
if ($(this).attr(“checked”)) {
$(‘input[name$=”CDSelect”]’).attr(‘checked’, ‘checked’);
} else {
$(‘input[name$=”CDSelect”]’).removeAttr(‘checked’);
}
});
});
Updated 15 July 2011:
In the new release of version 1.6.2 , it supports a new method called prop, you can use a new way to achieve the same thing as follow:
function ToggleAllCDs() {
$(‘input[name$=”CDSelectNew”]’).prop(“checked”, $(‘[name$=”CDSelectAllNew”]’).prop(“checked”));
}
$(document).ready(function () {
$(‘input[name$=”CDSelectAllNew”]’).click(ToggleAllCDs);
});
You can find the updated source code here.