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

2018-11-26 07:57:49来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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>

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:点击 Button触发事件将GridView1 CheckBox勾选的行添加到GridVi

下一篇:ASP.NET -- WebForm -- HttpResponse 类的方法和属性