In gridview header write like this:

<HeaderTemplate>
<asp:CheckBox runat=”server” ID=”cboxhead” AutoPostBack=”true” OnCheckedChanged=”HeaderCheckedChanged”/>
</HeaderTemplate>

In cs file

protected void HeaderCheckedChanged(object sender, EventArgs e)//this is for header checkbox changed event
{

CheckBox cbSelectedHeader = (CheckBox)GridView1.HeaderRow.FindControl(“cboxhead”);//if u checked header checkbox automatically all the check boxes will be checked,viseversa
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cbSelected = (CheckBox)row.FindControl(“CheckBox1”);
if (cbSelectedHeader.Checked == true)
{
cbSelected.Checked = true;

}
else
{
cbSelected.Checked = false;
}

}

}

Advertisements