Try this way:
Add a checkbox in header template:
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox2_CheckedChanged" />
</HeaderTemplate>
► and implement the checkedChange:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk1 = (CheckBox)GridView1.HeaderRow.FindControl("CheckBox2");
foreach (GridViewRow r in GridView1.Rows)
{
/* search id in itemtemplate */
CheckBox chkin = (CheckBox)r.FindControl("CheckBox1");
chkin.Checked = chk1.Checked;
}
}