header部分是全选的checkbox,item的部分是单个的checkbox部分。 (请注意AutoPostBack要设置为true,要不然无法触动服务器端的代码) 具体的后台的代码: 复制代码 代码如下: 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; } }