GridView和CheckBox连用,实现全选
<Columns>
<asp:TemplateField HeaderText="全选">
<ItemTemplate>
<asp:CheckBox ID="cb" runat ="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="quanxuan" runat="server" Text="全选" OnCheckedChanged="quanxuan_CheckedChanged" AutoPostBack="true"/>
</HeaderTemplate>
</asp:TemplateField>
--cs文件
protected void quanxuan_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox cb = gr.FindControl("cb") as CheckBox;
if (cb.Checked == false)
{
cb.Checked = true;
}
else
{
cb.Checked = false;
}
}
}