C# 在jQueryUI选项卡中的gridview中,SelectAll复选框选项仅在页面刷新后工作一次?

C# 在jQueryUI选项卡中的gridview中,SelectAll复选框选项仅在页面刷新后工作一次?,c#,javascript,jquery,asp.net,C#,Javascript,Jquery,Asp.net,我在一个应用程序中工作,我必须在标题中显示SelectAll复选框,它选择gridview中的所有行,并且在两个不同的jQueryUI选项卡中的页面中有两个不同的gridview 我的代码是 <head id="Head1" runat="server"> <script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script> <script src="Scripts/jque

我在一个应用程序中工作,我必须在标题中显示SelectAll复选框,它选择gridview中的所有行,并且在两个不同的jQueryUI选项卡中的页面中有两个不同的gridview

我的代码是

<head id="Head1" runat="server">
<script src="Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
                $("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox").click(function () {
                    //Get number of checkboxes in list either checked or not checked
                    var totalCheckboxes = $("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox").size();
                    //Get number of checked checkboxes in list
                    var checkedCheckboxes = $("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox:checked").size();
                    //Check / Uncheck top checkbox if all the checked boxes in list are checked
                    $("#<%=gvOpenTickets.ClientID%> input[id*='chkAll']:checkbox").attr('checked', totalCheckboxes == checkedCheckboxes);
                });

                $("#<%=gvOpenTickets.ClientID%> input[id*='chkAll']:checkbox").click(function () {
                    //Check/uncheck all checkboxes in list according to main checkbox 
                    $("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox").attr('checked', $(this).is(':checked'));
                });
            });
</script>
</head>

<asp:GridView ID="gvOpenTickets" TabIndex="11" runat="server" Height="176px" Width="100%"
                                                BackColor="#EEEEEE" Font-Size="10pt" Font-Names="Verdana" AutoGenerateColumns="False"
                                                HorizontalAlign="Left" DataKeyNames="IssueCategory,Type,userid,AssignedTo,Details,Id"
                                                Font-Name="Verdana" ShowHeaderWhenEmpty="false" ShowFooter="false" OnRowDataBound="gvOpenTickets_RowDataBound">
                                                <HeaderStyle Font-Bold="True" HorizontalAlign="Left" ForeColor="White" BackColor="Black">
                                                </HeaderStyle>
                                                <FooterStyle BorderColor="Black" BackColor="Black"></FooterStyle>
                                                <Columns>
                                                    <asp:TemplateField HeaderText="Date" HeaderStyle-Width="40px">
                                                        <ItemTemplate>
                                                            <asp:Label runat="server" Text='<%# Eval("TicketDate") %>' ID="lblDate" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Details" HeaderStyle-Width="230px">
                                                        <ItemTemplate>
                                                            <asp:Label runat="server" Text='<%# Eval("Details") %>' ID="lblDetails" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>

                                                    <asp:TemplateField>
                                                        <HeaderTemplate>
                                                            <asp:CheckBox runat="server" ID="chkAll" />
                                                        </HeaderTemplate>
                                                        <ItemTemplate>
                                                            <asp:CheckBox runat="server" ID="chkEmployee" />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                            </asp:GridView>

$(文档).ready(函数(){
$(“#输入[id*='chkEmployee']:复选框”)。单击(函数(){
//获取列表中已选中或未选中的复选框数
var totalcheckbox=$(“#输入[id*='chkEmployee']:复选框”).size();
//获取列表中选中复选框的数目
var checkedCheckboxes=$(“#输入[id*='chkEmployee']:复选框:选中”).size();
//如果选中了列表中的所有复选框,则选中/取消选中顶部复选框
$(“#输入[id*='chkAll']:复选框”).attr('checked',totalCheckboxes==checkedCheckboxes);
});
$(“#输入[id*='chkAll']:复选框”)。单击(函数(){
//根据主复选框选中/取消选中列表中的所有复选框
$(“#input[id*='chkEmployee']:checkbox”).attr('checked',$(this).is(':checked');
});
});

问题是,当我在页面刷新后单击标题行时,“全选”选项只起一次作用,然后它就不起作用了。

您可以将单击事件与.live as.绑定

$("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox").live("click", "chkEmployee", function (event) {
                    //Get number of checkboxes in list either checked or not checked
                    var totalCheckboxes = $("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox").size();
                    //Get number of checked checkboxes in list
                    var checkedCheckboxes = $("#<%=gvOpenTickets.ClientID%> input[id*='chkEmployee']:checkbox:checked").size();
                    //Check / Uncheck top checkbox if all the checked boxes in list are checked
                    $("#<%=gvOpenTickets.ClientID%> input[id*='chkAll']:checkbox").attr('checked', totalCheckboxes == checkedCheckboxes);
                });

最后将您的代码放入此函数。

您的代码是否在更新面板中?不,没有更新面板
chkEmployee.Attributes.Add("onclick","return YourFunctionname('"+chkEmployee.ClientId.ToString()+"')");