Click here to Skip to main content
14,216,534 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi

i need to get the total of this column at the end of grid view either as a column at the end or a label at the end of page .I am not using row_datadound event as i am direclty binding in the grid view.I need to get the sum of only this column.



<asp:TemplateField HeaderText="Invoice amount " HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="100px">
 <itemtemplate>
<asp:Label ID="lbInvoiceAmount" runat="server"  Text='<%# Bind("NetAmount") %>'>
        </itemtemplate>



Thanks much
Posted
Updated 5-Jul-12 19:48pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Here you will find the way to do it

http://csharpdotnetfreak.blogspot.com/2009/07/display-total-in-gridview-footer.html[^]

If you dont want to use the rowdatabound event then one way to do this is to get the result from database with Rollup. but if you do this you cannot use the gridview paging, you will have to have the paged results coming from the DB. Also, the last row will show the results and not the footer.
   
v2
Comments
Member 8155568 6-Jul-12 1:45am
   
Hi but in this also they are using row_databound event ....
Rahul Rajat Singh 6-Jul-12 1:48am
   
I have one more suggestion. check the updated answer.
Abhinav S 6-Jul-12 1:51am
   
5!
Rahul Rajat Singh 6-Jul-12 1:57am
   
thanks.
Member 8155568 6-Jul-12 6:11am
   
Thanks much it helped me a lot
Rahul Rajat Singh 6-Jul-12 6:12am
   
You are most welcome. always ready and glad to help a fellow developer.
Rate this:
Please Sign up or sign in to vote.

Solution 2

   
v3
Comments
Member 8155568 6-Jul-12 6:11am
   
Thanks much it helped me a lot
Rate this:
Please Sign up or sign in to vote.

Solution 3

   
Comments
Rahul Rajat Singh 6-Jul-12 2:22am
   
good link. +5.
Rate this:
Please Sign up or sign in to vote.

Solution 4

HI ,

you write a SP for total value and take one dummay table while adding all the rows put in for loop after completion of that you you call that sp and add it .

still if your not understand fell free to ask me. i will give code.

Regards
Aravind
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

Hi try this

in page load
if(!IsPostBack)

{
string sql="select sum(NetAmount) from table_name";
sqlcommand cmd=new sqlcommnad(sql,connectionstring);
cmd.connection=connectionstring;
con.open();
sqldatareader dr=cmd.executereader();
if(dr.Read())
{
textbox1.text=dr[0].tostring();
//or if u want in label just replace text to labelname
 
}
dr.close();
conc.close();


}


it will work for sure..try this..
if it is ur answer accept solution..
happy coding..
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100