具体代码如下:
#region 全选
protected void Button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
foreach (GridViewRow row in this.GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
(row.Cells[0].FindControl("CheckBox1") as CheckBox).Checked = btn.Visible;
}
}
}
#endregion
#region 全不选
protected void Button2_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
foreach (GridViewRow row in this.GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
(row.Cells[0].FindControl("CheckBox1") as CheckBox).Checked = !btn.Visible;
}
}
}
#endregion