Answered by:
Gridview Footer Total ,display in label outside of gridview and save in table.

Question
-
User-367318540 posted
i am display gridview footer Total of column in label which is in outside of gridview,but when i save it ,in database then value, which display in label which is outside of gridview does not save into database,when i debug it ,then it shows Text of label,not saving ,actual value which shows in label
//Calculate and update Grand Total. var grandTotal = 0; $("[id*=lbtotal2]").each(function () { grandTotal = grandTotal + parseFloat($(this).html()); }); $("[id*=lblGrandTotal]").html(grandTotal.toFixed().toString()); $("[id*=lbgtotal]").html(grandTotal);
label
<asp:Label ID="lbgtotal" runat="server" Text="total"></asp:Label>
Gridview
<asp:GridView ID="gvSelected" runat="server" AutoGenerateColumns = "false" Font-Names = "Arial" Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B" HeaderStyle-BackColor = "green" EmptyDataText = "No Records Selected" OnRowDataBound="gvSelected_RowDataBound" ShowFooter="True" > <Columns> <asp:BoundField ItemStyle-Width="0px" DataField="GRN_DID" HeaderText="ID" /> <asp:BoundField ItemStyle-Width="0px" DataField="GRN_ID" HeaderText="GRN" /> <asp:BoundField ItemStyle-Width="0px" DataField="It_ID" HeaderText="ITID" /> <asp:BoundField ItemStyle-Width="100px" DataField="imp_ibn_no" HeaderText="IB No" /> <asp:BoundField ItemStyle-Width="150px" DataField="imp_ibn_date" DataFormatString="{0:dd/MM/yyyy}" HeaderText="IB Date" /> <asp:BoundField ItemStyle-Width="150px" DataField="It_Name" HeaderText="Name" /> <asp:BoundField ItemStyle-Width="30px" DataField="grn_qty" HeaderText="QTY" /> <asp:BoundField ItemStyle-Width="30px" DataField="Cont" HeaderText="Container" /> <asp:TemplateField HeaderText="Rate" > <ItemTemplate> <asp:TextBox ID="txtrate" runat="server" Width="50px" Text='0'></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Amount" > <ItemTemplate> <asp:Label ID="lbtotal" runat="server" Width="50px" Text='<%#Bind("lbtotal")%>'></asp:Label> </ItemTemplate> <FooterTemplate> <%--<asp:Label ID="lblGrandTotals" runat="server"></asp:Label>--%> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Tax" > <ItemTemplate> <asp:Label ID="Im_Tax" runat="server" Width="50px" Class="calculate" Text='<%#Eval("Im_Tax")%>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Total" > <ItemTemplate> <asp:Label ID="lbtotal2" runat="server" Text='0' Width="50px" ></asp:Label> </ItemTemplate> <FooterTemplate> <asp:Label ID="lblGrandTotal" runat="server"></asp:Label> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Monday, July 6, 2020 8:20 PM
Answers
-
User-1330468790 posted
Hi akhterr,
Actually TextBox should be working. You should modify the javascript code a bit for the textbox.
For example, if you have use Textbox and HiddenField with Id "txtgtotal" and "hf_gtotal" respectively.
The js codes should be changed as below:
var grandTotal = 0; $("[id*=lbtotal]").each(function () { grandTotal = grandTotal + parseFloat($(this).html()); }); $("[id*=lblGrandTotal]").html(grandTotal.toString()); $("[id*=txtGrandTotal]").val(grandTotal.toString()); // input tag, use val() $("[id*=hf_grandTotal]").val(grandTotal.toString()); // input tag, use val()
The Footer Template is as below:
<FooterTemplate> <asp:Label ID="lblGrandTotal" runat="server"></asp:Label> <asp:Textbox ID="txtGrandTotal" runat="server"></asp:Textbox> <asp:HiddenField ID="hf_grandTotal" runat="server" /> </FooterTemplate>
However, I suggest you use HiddenField since it is not editable. What you need to do is simply passing the value back to server and storing the value into database.
Hope this can help you.
Best regards,
Sean
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 7, 2020 8:11 AM
All replies
-
User475983607 posted
akhterr
i am display gridview footer Total of column in label which is in outside of gridview,but when i save it ,in database then value, which display in label which is outside of gridview does not save into database,when i debug it ,then it shows Text of label,not saving ,actual value which shows in labelLabels are not input elements and updating labels in JavaScript does not update ViewState. Use input elements like hidden fields or textboxes if you need to accept input from the web form.
Monday, July 6, 2020 9:36 PM -
User-367318540 posted
I used Textbox ,but value is not showing in textbox
Tuesday, July 7, 2020 4:45 AM -
User-1330468790 posted
Hi akhterr,
Actually TextBox should be working. You should modify the javascript code a bit for the textbox.
For example, if you have use Textbox and HiddenField with Id "txtgtotal" and "hf_gtotal" respectively.
The js codes should be changed as below:
var grandTotal = 0; $("[id*=lbtotal]").each(function () { grandTotal = grandTotal + parseFloat($(this).html()); }); $("[id*=lblGrandTotal]").html(grandTotal.toString()); $("[id*=txtGrandTotal]").val(grandTotal.toString()); // input tag, use val() $("[id*=hf_grandTotal]").val(grandTotal.toString()); // input tag, use val()
The Footer Template is as below:
<FooterTemplate> <asp:Label ID="lblGrandTotal" runat="server"></asp:Label> <asp:Textbox ID="txtGrandTotal" runat="server"></asp:Textbox> <asp:HiddenField ID="hf_grandTotal" runat="server" /> </FooterTemplate>
However, I suggest you use HiddenField since it is not editable. What you need to do is simply passing the value back to server and storing the value into database.
Hope this can help you.
Best regards,
Sean
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 7, 2020 8:11 AM -
User-367318540 posted
Hi Sean Fang,
i have textbox outside of gridview not in footer ,i want footer total display in textbox ,which is outside of gridview ,Second thing is that if i used label instead of textbox it is showing value but when i insert into database then 0 value is being saved
Tuesday, July 7, 2020 8:42 AM