add value in grid view

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 27
Reputation: newcook88 is an unknown quantity at this point 
Solved Threads: 0
newcook88 newcook88 is offline Offline
Light Poster

add value in grid view

 
0
  #1
Sep 6th, 2009
how do i add two columns in a gridview and put the total in the third column

example

exam1 exam2 total
66 20 86


how to i create the colum to genrate the total aftrer doing the query in sql
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 42
Reputation: hericles is an unknown quantity at this point 
Solved Threads: 4
hericles hericles is offline Offline
Light Poster

Re: add value in grid view

 
0
  #2
Sep 7th, 2009
Hi,
If you're drawing the data for the first two columns out of a database, just add a third column into the SQL query that combines the two. Then databind the gridview to the resulting table.

E.g.
Select exam1, exam2, SUM(exam1 + exam2) as total from table;

If you need to do it after the query for some reason, add a new column to the resulting dataTable from the query and then loop through inserting the sum of the two columns together. Then databind the gridview once that is done.

Check this article out for an example of the code:
http://www.codersource.net/dataset_p..._addition.html

Hope that helps,
Hericles
MCP MCAD
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 27
Reputation: newcook88 is an unknown quantity at this point 
Solved Threads: 0
newcook88 newcook88 is offline Offline
Light Poster

Re: add value in grid view

 
0
  #3
Sep 7th, 2009
Thank you very much problem solved
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC