Below is the simple trick to select and unselect checkboxes inside gridview:-
Our Gridview has a Id called
grid_view_employee and
chk is our Header checkbox also in gridview.
function check_all_check_boxes(chk)
{
var grid_employee = document.getElementById('<%=grid_view_employee_details.ClientID %>');
if(grid_employee!=null)
{
for (row_index = 1;row_index <=grid_employee.rows.length-1;row_index++)
{
grid_employee.rows[row_index].cells[0].getElementsByTagName("input")[0].checked = chk.checked;
}
}
}
Now,call above function on Header Checkbox onclik event as shown below:- <asp:checkbox id="chk_check_all" runat="server" onclick = "check_all_check_boxes(this);"/>