How do you get the number of rows

I have a gridview and I want to display the total number of rows of data like 5000 rows?

This is not the same as the GridView1.Rows.Count, which gives the number of rows being displayed like 10 of 5000 rows.

How do I get at the total?

0
craigbtx
1/8/2006 8:12:17 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
943 Views

Similar Articles

[PageSpeed] 50

Hi,

i think what you are asking is how to get the number of rows of the bounded dataset. Lets say you bound a dataset to the grid, you only need to get the number of rows of the first table in the dataset:

myDataset.tables(0).rows.count

As simple as that!

 

regards,

njs

0
NJS
1/8/2006 8:36:21 PM

That works in ASP.NET 1.x

That doesn't work in ASP.NET 2.0s gridview unless I am missing something

0
craigbtx
1/8/2006 11:08:09 PM
You need to count the rows from the DataSource! 

HighOnCoding
Wanna get high!
0
azamsharp
1/9/2006 4:23:59 AM

You mean loop through the records incrementing a counter?

That means passing throught the results twice. Once to display the in a gridview and once to count the rows. Never had to do this in past versions. I don't think Microsoft would make you do this.

Isn't there a better way???

0
craigbtx
1/9/2006 12:55:03 PM

Hi,

I was playing with the SqlDataSource control last weekend and saw it can be done in the Selected event. This is completely out of my head but please try this:

e.AffectedRows    where e is of type SqlDataSourceStatusEventArgs

Grz, Kris.


Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
1/9/2006 1:08:31 PM
If your data is comming from Database and I assume it is then you can write a simple query that returns the total number of records in the table. 

Something like this:

SELECT COUNT(*) FROM MyTable

In the above query is will also return NULL rows if you don't want NULL rows then you can do something like this:

SELECT COUNT(MyTableID) FROM MyTable
where MyTableID is the primary key of the MyTable.

Hope it helps!

HighOnCoding
Wanna get high!
0
azamsharp
1/9/2006 2:11:20 PM
There is a count feature in a gridview.
0
SinkableHail
1/9/2006 2:13:20 PM

Awesome that is it!!!!

In the SqlDataSource1_Selected event use
e.AffectedRows to get the total number of rows in the datasource.

Looping through the rows and incrementing a counter or doing 2 selects against the database is not the best way. Imagine if you had millions of records, as I have!!!!! Plus in ASP.NET 1.1 all you had to do was Dataset.tblMyTable.count

0
craigbtx
1/9/2006 3:30:04 PM

craigbtx wrote:
Looping through the rows and incrementing a counter or doing 2 selects against the database is not the best way.

That's my thought also. There's no need to hit a database again when you have it already at your disposal.

Grz, Kris.


Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
1/9/2006 7:09:42 PM
Reply: