Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.



XML
<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

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.
 
Share this answer
 
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
 
Share this answer
 
v3
Comments
Member 8155568 6-Jul-12 6:11am    
Thanks much it helped me a lot
 
Share this answer
 
Comments
Rahul Rajat Singh 6-Jul-12 2:22am    
good link. +5.
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
 
Share this answer
 
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..
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900