Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

How to get the Total Value in the gridview footer

How can I get the Sum Total of Fee Amount in the footer of this datagrid.
and also how can I format the values to 45.00 adding the .00

or can I format the sql/server select statement for fee amount to .00

                                                                            Fee Amount

12/22/2009 11:00:00 AM  Strategies for Cultivating   45  1  12/16/2009 1:44:53 AM  
12/22/2009 11:00:00 AM  Strategies for Cultivating   45  1  12/16/2009 1:50:10 AM  
12/22/2009 11:00:00 AM  Strategies for Cultivating   45  1  12/16/2009 2:05:50 AM  

                                                                          Total    ??
0
westdh
Asked:
westdh
1 Solution
 
Anthony PerkinsCommented:
Since you posted in the MS SQL Server zone were you expecting a T-SQL solution?
0
 
westdhAuthor Commented:
yes
0
 
vipin_nagarroCommented:
Hi
For formatting use CAST(FeeAmount as DECIMAL(8 , 2))
For Total use one of the following:
1. Get total into the datatable as :
inserting all above values into a temp table, and then adding another row to it as attached.
 
2. AFTER Getting datatable as shown above, a row could be added inthe code as:
objectDataTable.Rows.Add(new object[]{ value1, value2,  objectDataTable.Select("SUM(FeeAmount)"), value 3, value4"}).
 
Thanks
Vipin Goel

SELECT * 
INTO #t
FROM --- WHERE ---

insert into #t
SELECT null, null, sum(feeAmount), null, ---
FROM --- WHERE --- 

SELECT * FROM #t

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Anthony PerkinsCommented:
It is quite simple then:

SELECT Col1, Col2, ... FeeAmount, ,.,
FROM YourTable
WHERE SomeCondition

UNION ALL

SELECT NULL, NULL, ... SUM(FeeAmount), ...
FROM YourTable
WHERE SomeCondition
0
 
rajeeshmcaCommented:
Hi westdh,

Instead of doing this in the sqlserver, you can achieve this using the rowdatabound event of the gridview like

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            DataTable objDataTable = (DataTable)(((GridView)sender).DataSource);
            ((Label)e.Row.FindControl("FooterLabel")).Text = objDataTable.Compute("Sum(FeeAmount)", "").ToString();
        }
    }
0
 
ROMA CHAUHANProject LeadCommented:
Hi westdh, You can get the total i code behind also but Better to do it from sql server.
It will be quick responsive.  Try the below one full working and tested query.

SELECT FDate, Description, FeeAmount,DispIndex,LDate
FROM FeesMaster

UNION 

SELECT NULL, NULL, CAST(SUM(FeeAmount) AS DECIMAL(18,2)), NULL,NULL
FROM FeesMaster
ORDER BY FeeAmount

Open in new window

0
 
Anthony PerkinsCommented:
Please do NOT use UNION when you should be using UNION ALL.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now