GridView添加模板列
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<input id="SelectAll" type="checkbox" />
</HeaderTemplate>
</asp:TemplateField>
JavaScript:
$("#SelectAll").click(function () {
if ($(this).attr("checked")) {
$('#GridView1 input[type=checkbox]').attr("checked", true);
}
else {
$('#GridView1 input[type=checkbox]').attr("checked", false);
}
});