Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview total.

Status
Not open for further replies.

stephenk1973

Technical User
Jun 11, 2003
246
GB
I have a a gridview in which i total a column, with pagination turned on it only totals 'what is visible'. How can i total all?

I had origionally though of 'copying' the gridview, turning off pagination and hiding all but the footer, but can't hide data rows.

What other suggestions have people got for solving this problem.

Thanks

Stephen
 
One way would be to do it in the SQL itself so that you can easily reference the counts (such as a ROLLUP query).

Alternatively, you could loop through your datasource and do a manual count.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I was thinking the second route, after all the data is already there, i whould be able to avoid quertying twice.

Are there any good sites you know of showing examples of loop through your sqldatasource?

Thanks
Stephen
 
You would loop through a datatable or datatable within a dataset.

Dim i as integer
For i = 0 to dt.Rows.Count - 1
... Do Something

Next i

Jim
 
If you went down the ROLLUP route, you wouldn't be querying the database twice (you would simply be amending the SQL to return the counts as another row).

As for looping throught the data source, you can set the DataSourceMode to whichever type you want (and faq855-5662 shows you how to loop through data from a database).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
i usually set up a session variable for the total that i want...

then in the itemdatabound event add to that variable and post it in the footer...

"...your mom goes to college..."
 
I don't think using a session variable will help. The posters problem is that they are using Paging so the ItemDataBound event will only fire for each record that is shown and therefore the total will not be the total for the whole column (if I have understood their problem correctly anyway).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
ca8sum is correct the problem is caused by the pagination, only loaded rows are looped through.

Have looked at the examples, they bind the source and requery, is there a way of working on the sqldatasource i already have???

I currently pull this back using a second stored procedure and gridview box.

Thanks

Stephen
 
is there a way of working on the sqldatasource i already have???
Yes. As I said above, you can set the DataSourceMode of the SqlDataSource and loop through the data however you want (using the Select method).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top