Use This Java Script
function SelectAll(id) {
var frm = document.forms[0];
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox") {
frm.elements[i].checked = document.getElementById(id).checked;
}
}
Use this Code For Check Box Inside gridview...
<asp:templatefield >
<headertemplate>
<asp:checkbox id="chkSelectAll" runat="server" />
</headertemplate>
</asp:templatefield>
Add Row Data Bound Event and in .cs file call this javascript...
protected void gdvTest_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
((CheckBox)e.Row.FindControl("chkSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("chkSelectAll")).ClientID + "')");
}
}