Click here to Skip to main content
12,954,672 members (67,796 online)
Rate this:
 
Please Sign up or sign in to vote.
I have a few dropdowns in my gridview, each has 2 same options, I want to calculate out of all these dropdowns how many times is option1 selected (selectedIndex = 1) and how many times the second option is selected (selectedIndex = 2) using jQuery.
    <asp:GridView ID="gd1" runat="server" AutoGenerateColumns="False"
            onrowdatabound="gd1_RowDataBound" >
            <Columns>
                       <asp:BoundField DataField="id"   Visible="False"/>
                       <asp:BoundField DataField="fullName" Visible="True"
            HeaderText="Full Name"/>
                          <asp:TemplateField >
                              <ItemTemplate>
     <asp:DropDownList ID="ddl1" runat="server" ></asp:DropDownList>
                            </ItemTemplate>
                          </asp:TemplateField>
 
                          <asp:TemplateField >
                              <ItemTemplate>
     <asp:DropDownList ID="ddl2" runat="server"></asp:DropDownList>
                            </ItemTemplate>
                          </asp:TemplateField>
 
                          <asp:TemplateField >
                              <ItemTemplate>
     <asp:DropDownList ID="ddl3" runat="server"></asp:DropDownList>
                            </ItemTemplate>
                          </asp:TemplateField>
 
                          <asp:TemplateField>
                              <HeaderTemplate>
              <asp:Label ID="Count1" runat="server" Text="First Count"></asp:Label>
                              </HeaderTemplate>
                              <ItemTemplate>
              <asp:Label ID="CountSelected1" runat="server" ></asp:Label>
                              </ItemTemplate>
                          </asp:TemplateField>
 
                          <asp:TemplateField>
                              <HeaderTemplate>
           <asp:Label ID="Count2" runat="server" Text="Second Count"></asp:Label>
                              </HeaderTemplate>
                              <ItemTemplate>
               <asp:Label ID="CountSelected2" runat="server" ></asp:Label>
                              </ItemTemplate>
                          </asp:TemplateField>
           </Columns>
 </asp:GridView>

In the final 2 columns I want to display the total number of selections of option1 and option2.
Posted 4-Sep-12 0:35am
Updated 5-Sep-12 5:24am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

final code that works:
var collection = $('select.ddlJ');
 
for (var element in collection)
$(element).change(function(){})
 
 $(function() {
    $('select.ddlJ').change(function(e) {
        $(this).parent().parent().find('td:last').prev().find('span').html( 
            $(this).parent().parent().find( 'select.ddlJ' ).filter(function() {
                return $.trim($(this).val()) == 'm';
            }).length
         );
        $(this).parent().parent().find('td:last span').html( 
            $(this).parent().parent().find( 'select.ddlJ' ).filter(function() {
                return $.trim($(this).val()) == 'n';
            }).length
         );
    });
});
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100