Reputation: 4259
happy new year to all,
i am having a problem in counting subtotal in a gridview in asp.net
the gridview contains details like
sl .no item reading result
1 A [userentry]
2 [userentry]
3 [userentry] [labeltodispresult]
1 B [userentry]
2 [userentry]
3 [userentry] [labeltodispresult]
i need to calculate the sum of the user entry for each item and display into the resultant lable.
let me tell you what i have achived, i am facing no problem at all in the gridview part. when ever the user entry is made the value in the result lable should be updated, i am binding a javascript function to the userentry textbox in rowdatabound event in code behind. in the javascript i am able to roll over all the rows of table using jquery, and calculate the value. here is the catch, the labletodispresult should be for that item group only, i.e. i need to get the sum of userentry for A -1,A-2, A-3 rows and seperately for B-1,B-2,B-3 rows, the i am using a class for the userentry textbox, and using this
<asp:gridview id="gv1" runat="server">
<columns>
<ItemTemplate headertext="sl.no">
<asp:label id="lblslno" runat="server" text='<%# Eval("slno")%>' />
</ItemTemplate>
<ItemTemplate headertext="Item">
<asp:label id="lblItem" runat="server" text='<%# Eval("Item")%>' />
</ItemTemplate>
<ItemTemplate headertext="readings">
<asp:TextBox id="txtReadings" runat="server" class="readings" />
</ItemTemplate>
<ItemTemplate headertext="result">
<asp:label id="lblresult" runat="server" />
</ItemTemplate>
</columns>
</asp:gridview>
jquery part:
function calculate(){
$('.readings').each(function(){
sumval +=parseFloat($(this).val());
});
}
this gives me all the textboxes sum value, but i need the values based on the Item group. i am at a fix any help?
Upvotes: 0
Views: 1591
Reputation: 7276
Here is one thing you can try. Set the class of your textbox = your item i.e.
CssClass='<%# Eval("Item")%>'
That is one way to differentiate your textboxes based on item. Then get your textbox based on that class.
Upvotes: 1