Prerequisite: include JQuery script file
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
This tip is to create a "Check All" checkbox which will select all the checkboxes in the grid or on the page or if you uncheck individual check box, then it will uncheck the "Select All"check box.
If the check box is disabled, then it will not inlude this in the selection.
This is the aspx code:
<script language="javascript" type="text/javascript">
$(document).ready(
function(){
$('#chkSelectAll').click(
function(){
$('input:checkbox:not(:disabled)').not('#chkSelectAll').click(
function()
{
if($('input:checkbox:not(:disabled, :checked)').not('#chkSelectAll').length == 0)
$('#chkSelectAll').attr('checked', true)
else
$('#chkSelectAll').attr('checked', false)
}
).attr('checked', this.checked);
})
}
);
</script>
<table width="150" id="ttt">
<tr>
<td>
<asp:CheckBox ID="chkSelectAll" runat="server" Text="Select All" />
<br />
<asp:CheckBox ID="chkBx1" runat="server" Text="CheckBox 1" Enabled="false" />
<br />
<asp:CheckBox ID="chkBx2" runat="server" Text="CheckBox 2" />
<br />
<asp:CheckBox ID="chkBx3" runat="server" Text="CheckBox 3" />
<br />
<asp:CheckBox ID="chkBx4" runat="server" Text="CheckBox 4" />
</td>
</tr>
</table>