时间:2021-07-01 10:21:17 帮助过:8人阅读
<asp:TemplateField HeaderText="全选">
<HeaderTemplate>
<input type="checkbox" id="CheckBox1" name="CheckBox1" onclick="GetAllCheckBox(this)" />
全选
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server"/>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="100px" />
</asp:TemplateField>
2.编写JS代码
代码如下:
<script type="text/javascript" language="javascript">
function GetAllCheckBox(CheckAll)
{
var items = document.getElementsByTagName("input");
for(var i=0;i<items.length;i++)
{
if(items[i].type == "checkbox")
{
items[i].checked = CheckAll.checked;
}
}
}
</script>