tags:

views:

407

answers:

5

I have a gridview that shows (50)rows of data per page. I have the Total showing for the Amount that is shown due to a previous request by the user. Now they want to have the total for the Entire result, regardless of what page they are on. How do I do that?

I did the following for my Complete Total Count:

After the Gridview result gets populated in table

Count = dsReport.DataTable1.Count;

My plan for the Complete Total that has so far failed:

for (int i = 0; i < Count; i++) 
{ Total += dsPoint.DataTable1.Columns[3].Row[i]; ??? I dont know what to do }

What is the sum of the specific Decimal Column[3]? Even though I display 50 results, I need the Total for the ENTIRE column.

A: 

What is the total that you are looking for. Just the total number of records in the datatable or a sum of a specific column.

the sum of a specific column, but even tho i have a restriction of 50 being displayed, I still want the total for the ENTIRE result.
A: 

It looks like you have it backwards. Typically to get to a value in a DataTable you'll want to use DataTable.Row[i].Column[j]. So assuming you have an integer in your column, you can run your total like this:

for (int i = 0; i < Count; i++) 
{ 
   Total += Integer.Parse(dsPoint.DataTable1.Rows[i].Columns[3];
}
Dillie-O
a. I have a decimal, sorryb. it doesnt work
A: 

You could look at the Compute method of the datatable. It is much easier than looping through the datatables.

Conrad
+3  A: 

Something like ...

Total = dsPoint.Tables["DataTable1"].Compute("SUM(columnName)", String.Empty);

You provide columnName :)

JP Alioto
Hey look at that! I learned something new!
Dillie-O
A: 

See this: http://www.aspalliance.com/494