怎樣添加設置GridView,CheckBox全選功能

GridView內CheckBox控件全選設置

不需要添加後台代碼操作,前端即可完成設置,如下:

前端代碼:

1.設置javascript。

<html xmlns="http://www.w3.org/1999/xhtml" >
<script type="text/javascript">

function CheckAll3(oCheckbox)
{
var GridView3 = document.getElementById("<%=GridView1.ClientID %>");
for(var i = 1; i < GridView1.rows.length; i++)
{
GridView1.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = oCheckbox.checked;
}

}
</script>

2.body內代碼:

<asp:GridView ID="GridView1" runat="server" Height="2px" Width="720px" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="1" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="False" PageSize="8" >
<RowStyle ForeColor="#000066" />
<FooterStyle BackColor="White" ForeColor="#000066" />

<Columns>

<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:Label ID="lbuid" runat="server" Visible="false" Text='<%# Eval("data") %>'></asp:Label>
</ItemTemplate>
<HeaderTemplate>
<input type="checkbox" id="ChkHead" onclick="CheckAll3(this)" title="選擇全部" />
<%--<asp:CheckBox ID="CheckBoxALL" runat="server" AutoPostBack="True" />--%>
</HeaderTemplate>
<HeaderStyle Width="20px" />
<ItemStyle Width="20px" />

</asp:TemplateField>
                            <asp:BoundField DataField="data" HeaderText="日期(data)" ReadOnly="True" />
                            <asp:BoundField DataField="users" HeaderText="姓名(users)" SortExpression="姓名" />
                            <asp:BoundField DataField="user_name" HeaderText="賬號(user_name)"  />
                            <asp:BoundField DataField="user_email" HeaderText="郵箱(user_email)"  />
                            <asp:BoundField DataField="mony" HeaderText="金額(mony)" />

</Columns>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" CssClass="Freezing" />

</asp:GridView>

上一篇:spring RedisTemplate的使用(一)--xml配置或JavaConfig配置


下一篇:Java DecimalFormat 用法(数字格式化)