<script language="javascript">
function CheckAllC(oCheckbox)
{
var gvList = document.getElementById("<%=GridView1.ClientID %>");
for(i = 1;i < gvList.rows.length; i++)
{
gvList.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
}
}
</script>
HTML代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" cssclass="viewcolor" AllowPaging="True" PageSize="12" OnPageIndexChanging="GridView1_PageIndexChanging1" AllowSorting="True" OnSorting="GridView1_Sorting">
<Columns>
<asp:TemplateField HeaderText="发布">
<HeaderTemplate>
<input id="Checkbox1" type="checkbox" onclick="javascript:CheckAllC(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
function CheckAllC(oCheckbox)
{
var gvList = document.getElementById("<%=GridView1.ClientID %>");
for(i = 1;i < gvList.rows.length; i++)
{
gvList.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
}
}
</script>
HTML代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" cssclass="viewcolor" AllowPaging="True" PageSize="12" OnPageIndexChanging="GridView1_PageIndexChanging1" AllowSorting="True" OnSorting="GridView1_Sorting">
<Columns>
<asp:TemplateField HeaderText="发布">
<HeaderTemplate>
<input id="Checkbox1" type="checkbox" onclick="javascript:CheckAllC(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>