1

我正在尝试使用 javascript 读取网格视图中选定行的数量。为此,我想计算选择列中选中复选框的数量。目前我的gridview的列是这样设置的:

        <asp:TemplateField HeaderText="Select">
            <EditItemTemplate>
                <asp:CheckBox ID="SelectedBox" runat="server" />
            </EditItemTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="SelectedBox0" runat="server" />
            </ItemTemplate>
            <HeaderStyle CssClass="SelectHeader" />
            <ItemStyle CssClass="CheckBoxes" />
        </asp:TemplateField>

        <asp:BoundField DataField="WSUID" HeaderText="WSUID"
            SortExpression="WSUID" />
        <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
        <asp:BoundField DataField="Email" HeaderText="Email" 
            SortExpression="Email" />
        <asp:BoundField DataField="FullName" HeaderText="Full Name" 
            SortExpression="FullName" />
        <asp:BoundField DataField="MailAddress1" HeaderText="Mailing Address" 
            SortExpression="MailAddress1" />
        <asp:BoundField DataField="MailAddress2" HeaderText="Mail Address 2" Visible="false"
            SortExpression="MailAddress2" />
        <asp:BoundField DataField="MailCity" HeaderText="City" 
            SortExpression="MailCity" />
        <asp:BoundField DataField="MailState" 
            HeaderText="State" 
            SortExpression="MailState" />
        <asp:BoundField DataField="MailZip" 
            HeaderText="Zip" SortExpression="MailZip" />
        <asp:BoundField DataField="RegistrationSession" HeaderText="Session Info" 
            SortExpression="RegistrationSession" />
        <asp:BoundField DataField="Guests" HeaderText="CountGuest" 
            SortExpression="Guests" ReadOnly="True" />
        <asp:BoundField DataField="TotalOwed" 
            HeaderText="ToChai" SortExpression="TotalOwed" 
            ControlStyle-BorderStyle="NotSet" />
        <asp:BoundField DataField="TotalPaid" HeaderText="ToPai" ReadOnly="True" 
            SortExpression="TotalPaid" />
        <asp:BoundField DataField="Balance" HeaderText="BalDu" 
            SortExpression="Balance" ReadOnly="True" />
        <asp:CheckBoxField DataField="IsInternational" 
            HeaderText="International Student" SortExpression="IsInternational" />
        <asp:BoundField DataField="SessionNumber" HeaderText="Session Number" 
            SortExpression="SessionNumber" />
        <asp:BoundField DataField="LastName" HeaderText="SLName" 
            SortExpression="LastName" Visible="False" />

        <asp:BoundField DataField="NameAddressed" HeaderText="Name Addressed" 
            SortExpression="NameAddressed" />
        <asp:CheckBoxField DataField="CancelReservation" HeaderText="Cancel Reservation" 
            SortExpression="CancelReservation" ReadOnly="false" Visible="False" />
        <asp:BoundField DataField="CommunicationPreferrence" 
            HeaderText="Communication Preference" 
            SortExpression="CommunicationPreferrence" />
    </Columns>

选择是第一列。到目前为止,我尝试使用:

<script type="text/javascript">
    function myFunction() {

        var numEmails = $("[type='checkbox']:checked").length;
        $("#<%=gvMailMergeExport.ClientID%> input[id*='SelectedBox']:checkbox").each(function (index) {
            if ($(this).is(':checked'))
                numEmails++;
        });

    }
</script>

要计算选定行的数量,但此函数还会计算另一列复选框,并大大减少了计数。有没有办法只计算gridview的一列中的复选框数量?

4

0 回答 0