JaimeJegonia
asked on
Total on the Grid Footer
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_ARAg ing" %>
<!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_RowDataBou nd(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
try
{
// add the UnitPrice and QuantityTotal to the running total variables
Thirty += Convert.ToDouble((DataBind er.Eval(e. Row.DataIt em, "30 Days")).ToString());
Sixty += Convert.ToDouble((DataBind er.Eval(e. Row.DataIt em, "31-60")).ToString());
Ninety += Convert.ToDouble(DataBinde r.Eval(e.R ow.DataIte m, "61-90"));
OneTwenty += Convert.ToDouble(DataBinde r.Eval(e.R ow.DataIte m, "91-120"));
Over120 += Convert.ToDouble(DataBinde r.Eval(e.R ow.DataIte m, "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].HorizontalA lign = e.Row.Cells[2].HorizontalA lign = e.Row.Cells[3].HorizontalA lign = e.Row.Cells[4].HorizontalA lign = e.Row.Cells[5].HorizontalA lign = 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="SqlDataSourc e1" GridLines="Horizontal" ShowFooter="True" OnRowDataBound="detailsGri dView_RowD ataBound">
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyNam e" />
<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:TradingC onnectionS tring %>"
SelectCommand="a_spARAging " SelectCommandType="StoredP rocedure"> </asp:SqlD ataSource>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ARAging.aspx.cs"
<!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_RowDataBou
{
if (e.Row.RowType == DataControlRowType.DataRow
{
try
{
// add the UnitPrice and QuantityTotal to the running total variables
Thirty += Convert.ToDouble((DataBind
Sixty += Convert.ToDouble((DataBind
Ninety += Convert.ToDouble(DataBinde
OneTwenty += Convert.ToDouble(DataBinde
Over120 += Convert.ToDouble(DataBinde
}
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].HorizontalA
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
BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSourc
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyNam
<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:TradingC
SelectCommand="a_spARAging
</div>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One other question: My demo assumed that your numeric colums were of SQL type float. Is this the case?
ASKER
NovyNov,
It's just a footer rendering problem. The SQL type is decimal(14,2).
Thanks,
It's just a footer rendering problem. The SQL type is decimal(14,2).
Thanks,
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?
When you breakpoint on the Footer row section, does the code get executed? Are the cell values assigned correctly at least in this call?
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?
ASKER
Thanks. I think my problem is with the null value.
Please see my pivot result against grid total view.
Error.PNG
Please see my pivot result against grid total view.
Error.PNG
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.
ASKER
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
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
ASKER
Thanks for the help & time.
ASKER
There's no change in my SP but "ArgumentNullException" tweak in C# page.
Corrected.PNG
Corrected.PNG