protected void CheckAll_CheckedChanged(object sender,EventArgs e) { CheckBox ck = sender as CheckBox; if (ck != null) { System.Web.UI.WebControls.GridView g = ck.NamingContainer.NamingContainer as System.Web.UI.WebControls.GridView; for (Int32 i = 0; i < g.Rows.Count; i++) { (g.Rows[i].FindControl("CheckBox1") as CheckBox).Checked = ck.Checked; } } } protected void CheckBox1_CheckedChanged(object sender,EventArgs e) { var count = 0; CheckBox ck = sender as CheckBox; if (ck != null) { System.Web.UI.WebControls.GridView g = ck.NamingContainer.NamingContainer as System.Web.UI.WebControls.GridView; for (Int32 i = 0; i < g.Rows.Count; i++) { if ((g.Rows[i].FindControl("CheckBox1") as CheckBox).Checked) { count++; } } (g.HeaderRow.FindControl("CheckAll") as CheckBox).Checked =count==g.Rows.Count; } }