View Single Post
Old July 7th, 2005, 04:46 PM
Imar's Avatar
Imar Imar is offline
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Either I am not understanding what you want, or you are missing a few concepts.

If you're not using paging, the DataGrid displays all records. Thus, the Items.Count returns all records currently displayed in the grid.

If you want to know all the records in the initial data source, ask the datasource ;)
Suppose you create a dataset with a query like this:

SELECT Col1, Col2 FROM YourTable WHERE SomeCriteria = SomeValue.

Let's say your *database* table holds 100 records, and that 20 are returned by this query. Let's also say your Grid has a PageSize of 10

Then this:


returns 20, as that is the number of records in a *DataTable* inside the DataSet, not the total number of records in the table in the *database*.


MyDataGrid.Items.Count returns 10

and this:


returns 100

So, now you can count whatever you want: items in the grid (Items.Count), items in the datasource (Tables(0).Rows.Count) or items in the database table (SELECT COUNT(*) FROM YourTable)

Is there anything more to count??

Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: You Think I Ain't Worth A Dollar, But I Feel Like A Millionaire by Queens of the Stone Age (Track 2 from the album: Songs For The Deaf) What's This?