?
Solved

Total on the Grid Footer

Posted on 2008-10-08
10
Medium Priority
?
302 Views
Last Modified: 2013-12-17
I am wondering why my total footer is always zero(0): this is my code;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ARAging.aspx.cs" Inherits="tblCustomer_ARAging" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Double Thirty;
    Double Sixty;
    Double Ninety;
    Double OneTwenty;
    Double Over120;
   
    void detailsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            try
            {
                // add the UnitPrice and QuantityTotal to the running total variables
                Thirty += Convert.ToDouble((DataBinder.Eval(e.Row.DataItem, "30 Days")).ToString());
                Sixty += Convert.ToDouble((DataBinder.Eval(e.Row.DataItem, "31-60")).ToString());
                Ninety += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "61-90"));
                OneTwenty += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "91-120"));
                Over120 += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "Over 120"));
            }
            catch
            {
             //  
            }
           
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[0].Text = "Totals:";

            // for the Footer, display the running totals
            e.Row.Cells[1].Text = Thirty.ToString("n");
            e.Row.Cells[2].Text = Sixty.ToString("n");
            e.Row.Cells[3].Text = Ninety.ToString("n");
            e.Row.Cells[4].Text = OneTwenty.ToString("n");
            e.Row.Cells[5].Text = Over120.ToString("n");
           
            e.Row.Cells[1].HorizontalAlign = e.Row.Cells[2].HorizontalAlign = e.Row.Cells[3].HorizontalAlign = e.Row.Cells[4].HorizontalAlign = e.Row.Cells[5].HorizontalAlign = HorizontalAlign.Right;
            e.Row.Font.Bold = true;
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Aging Receivable</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
       
            BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1" GridLines="Horizontal" ShowFooter="True" OnRowDataBound="detailsGridView_RowDataBound">
           
            <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
            <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
            <Columns>
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="30 Days" HeaderText="30 Days" SortExpression="30 Days" DataFormatString="{0:n}"/>
                <asp:BoundField DataField="31-60" HeaderText="31-60" SortExpression="31-60" DataFormatString="{0:n}"/>
                <asp:BoundField DataField="61-90" HeaderText="61-90" SortExpression="61-90" DataFormatString="{0:n}"/>
                <asp:BoundField DataField="91-120" HeaderText="91-120" SortExpression="91-120" DataFormatString="{0:n}"/>
                <asp:BoundField DataField="Over 120" HeaderText="Over 120" SortExpression="Over 120" DataFormatString="{0:n}"/>
            </Columns>
            <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
            <AlternatingRowStyle BackColor="#F7F7F7" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TradingConnectionString %>"
            SelectCommand="a_spARAging" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
   
    </div>
    </form>
</body>
</html>
 
0
Comment
Question by:JaimeJegonia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 4

Accepted Solution

by:
novynov earned 1500 total points
ID: 22674378
So, I wrote a little demo app to try what you were doing and it worked fine. The only real difference was that I didn't do any gridview styling - that shouldn't matter. At first I thought the problem might lie with the column names - they aren't valid C# identifier names...so might have caused the databinder to have problems. But, that wasn't it. I did it fine with identical column names.

Have you put a debugger on the rowdatabound handler? Are the totals at least getting accumulated? It would be good to know if the problem lies in the evaluation and storing of the value, or if it is just a  footer rendering problem. That would at least partition the troubleshooting space.

Let me know. I'll be glad to help more.
0
 
LVL 4

Expert Comment

by:novynov
ID: 22674397
One other question: My demo assumed that your numeric colums were of SQL type float. Is this the case?
0
 

Author Comment

by:JaimeJegonia
ID: 22674423
NovyNov,

It's just a footer rendering problem. The SQL type is decimal(14,2).

Thanks,


0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 4

Expert Comment

by:novynov
ID: 22674494
Very strange: I changed my sql type to match yours, and basically copied your code into a new page verbatim - the only exception is that my db only has 3 of the numeric fields, not 5. All worked well.

When you breakpoint on the Footer row section, does the code get executed? Are the cell values assigned correctly at least in this call?
0
 
LVL 4

Expert Comment

by:novynov
ID: 22674540
So, maybe a long shot, but given that I don't see the source for your code behind in your posting above, ARAging.aspx.cs, is it possible that something in there is blowing away the values?
0
 

Author Comment

by:JaimeJegonia
ID: 22674561
Thanks. I think my problem is with the null value.
Please see my pivot result against grid total view.

 

Error.PNG
0
 
LVL 4

Expert Comment

by:novynov
ID: 22677439
Ahhh...possibly, although you said that the totals were getting calculated correctly in the DataRow section of your event handler. Can you copy in your stored procedure. I'll try to reproduce the results and come up with a solution.
0
 

Author Comment

by:JaimeJegonia
ID: 22683322
novynov:

I solved my issue by creating a small conversion function that catches "ArgumentNullException" and return to zero (0).

Anyways, thanks for helping me to come up with the solution and I'll still give you the points.

Jimi  
0
 

Author Closing Comment

by:JaimeJegonia
ID: 31504139
Thanks for the help & time.
0
 

Author Comment

by:JaimeJegonia
ID: 22683357
There's no change in my SP but "ArgumentNullException" tweak in C# page.
Corrected.PNG
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question