当前位置: 移动技术网 > IT编程>开发语言>.net > 怎樣添加設置GridView,CheckBox全選功能

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

2018年11月26日  | 移动技术网IT编程  | 我要评论

南通有哪些大学,杨一展个人资料,电脑知识入门

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>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网