<asp:CheckBox ID="CheckAll" runat="server" Text="全选" OnCheckedChanged="selectAll" AutoPostBack="True" />
protected void selectAll(object sender, EventArgs e)
{
//如果选中,则全选;否则,取消选择
if (CheckAll.Checked == false)
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)(GridView1.Rows[i].Cells[0].FindControl("ChBSelect"));
chk.Checked = false;
}
}
else
{
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)(GridView1.Rows[i].Cells[0].FindControl("ChBSelect"));
chk.Checked = true;
}
}
}
转载于:https://www.cnblogs.com/kangranran/archive/2007/07/25/831075.html