与多个复选框列GridView和选择全部列标题 [英] GridView with Multiple Checkbox Columns and Select All Column Header

查看:113
本文介绍了与多个复选框列GridView和选择全部列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net的GridView的头,我有两列

 列中选择所有的员工|列中选择所有用人单位

所以我有两个复选框两列,所以一旦点击选择所有员工只应选择全体员工,并与用人单位也是如此。

但低于code是选择雇员和雇主如果只对雇主的选择。

 函数SelectAllCheckboxes(CHK){
        $('#<%= gv.ClientID%GT;')找到(输入:复选框)。每个(函数(){
            如果(这= CHK!){this.checked = chk.checked; }
        });
    }    功能SelectAllCheckboxes1(CHK){
        $('#<%= gv.ClientID%GT;')找到(输入:复选框)。每个(函数(){
            如果(这= CHK!){this.checked = chk.checked; }
        });
    }
< ASP:复选框ID =chkAll=服务器的onclick =JavaScript的:SelectAllCheckboxes(本); />< ASP:复选框ID =chkAll1=服务器的onclick =JavaScript的:SelectAllCheckboxes1(本); />


解决方案

ASP - 在你的GridView:

 < ASP:GridView控件ID =GV=服务器>
    < ASP:的TemplateField>
        <&ItemTemplate中GT;
            < ASP:复选框ID =cbxSelectEmployer=服务器的CssClass =雇主/>
        < / ItemTemplate中>
    < / ASP:的TemplateField>
    < ASP:的TemplateField>
        <&ItemTemplate中GT;
            < ASP:复选框ID =cbxSelectEmployee=服务器的CssClass =雇员/>
        < / ItemTemplate中>
    < / ASP:的TemplateField>
< / ASP:GridView的>

ASP - 全选复选框:

 < ASP:复选框ID =chkAll=服务器的onclick =SelectAllCheckboxes(这一点,.employee')/>
< ASP:复选框ID =chkAll1=服务器的onclick =SelectAllCheckboxes(这一点,.employer')/>

jQuery的

 函数SelectAllCheckboxes(CHK,选择器){
    $('#<%= gv.ClientID%GT;')找到(选择+输入:复选框)。每个(函数(){
        $(本).prop(选中,$(CHK).prop(选中));
    });
}

i am using asp.net gridview in header i have two columns

column select all employee  | column select all employer

so i have two checkbox for two columns, so once it click on the select all employee it should only be selected for all employee and same goes with employer

but the below code is selecting both employee and employer if only select on employer.

function SelectAllCheckboxes(chk) {
        $('#<%=gv.ClientID%>').find("input:checkbox").each(function () {
            if (this != chk) { this.checked = chk.checked; }
        });
    }

    function SelectAllCheckboxes1(chk) {
        $('#<%=gv.ClientID%>').find("input:checkbox").each(function () {
            if (this != chk) { this.checked = chk.checked; }
        });
    }


<asp:CheckBox ID="chkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this);" />

<asp:CheckBox ID="chkAll1" runat="server" onclick="javascript:SelectAllCheckboxes1(this);" />

解决方案

ASP - in your GridView:

<asp:GridView id="gv" runat="server">
    <asp:TemplateField>
        <ItemTemplate>
            <asp:CheckBox id="cbxSelectEmployer" runat="server" CssClass="employer" />
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:CheckBox id="cbxSelectEmployee" runat="server" CssClass="employee" />
        </ItemTemplate>
    </asp:TemplateField>
</asp:GridView>

ASP - "Select all" checkboxes:

<asp:CheckBox ID="chkAll" runat="server" onclick="SelectAllCheckboxes(this, '.employee')" />
<asp:CheckBox ID="chkAll1" runat="server" onclick="SelectAllCheckboxes(this, '.employer')" />

jQuery

function SelectAllCheckboxes(chk, selector) {
    $('#<%=gv.ClientID%>').find(selector + " input:checkbox").each(function () {
        $(this).prop("checked", $(chk).prop("checked"));
    });
}

这篇关于与多个复选框列GridView和选择全部列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆