Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET jQuery Gridview
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
Edited 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
0 Sergey Alexandrovich Kryukov 359
1 _Amy 230
2 Manfred R. Bihy 200
3 CHill60 180
4 OriginalGriff 175
0 OriginalGriff 7,495
1 Sergey Alexandrovich Kryukov 6,402
2 Maciej Los 3,849
3 Peter Leow 3,568
4 CHill60 2,702


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2014
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