Selecting checkboxes inside the GridView control is a very common operation and that is why I have several articles and videos dedicated to this subject.
Selecting CheckBoxes Inside GridView With a Twist
VIDEO: Selecting CheckBoxes Inside GridView
Recently, I was playing around with JQuery library and thought of implementing the same scenario using the library. Here is the code used to perform the SelectAll and DeSelectAll function.
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$("#chkAll").click(function()
{
// I don't like this line!
this.checked = !(this.checked == true);
$("#gvCategories input:checkbox").attr("checked",function()
{
this.checked = !(this.checked == true);
});
});
});
</script>
Yup! that's all the code you need to perform this operation. If you think you can even refactor this out then please post your refactorings at Selecting CheckBoxes Inside the Table.