Set maximum Rows to be displayed in a datagrid

N

Nicolaj

How do I set the maximum number of rows for a datagrid when binding a
datareader to it?

I am presently using:

OracleDataReader dr = getResults( parameters ); //returns a datareader
if (dr.HasRows)
{
dgSomeDatagrid.DataSource = dr;
dgSomeDatagrid.DataBind();
}
else
///

I've also implemented the ItemDataBound event for certain calculations.
No paging etc is implemented.
Now, for example I get the last transactions done by someone for the
past 5 months. I only want to display 10 records here. How do I go
about that?
Also, the datagrid is actually in a user control which I use in a few
other places as well and display all results there.

Regards,

Nicolaj
 
N

Nicolaj

Oh, and I have a workaround for now. I've enable paging and disabled
the navigation controls. But it seems a waste of resources still.
Hopefully, there will be a better way.
How do I set the maximum number of rows for a datagrid when binding a
datareader to it?
*SNIP*

Regards,

Nicolaj
 
R

Riki

Nicolaj said:
How do I set the maximum number of rows for a datagrid when binding a
datareader to it?

The best way is to limit the number of records in the SELECT statement:
SELECT TOP 10 * FROM mytable ORDER BY myfield;
 
N

Nicolaj

Riki said:
The best way is to limit the number of records in the SELECT statement:
SELECT TOP 10 * FROM mytable ORDER BY myfield;

Yes, I know. But unfortunately I get the data via a stored procedure
which cannot be changed as the same procedure is being used for
displaying all the data in other grids in my web application. It's just
in this one place where I need to show only 10 results.

How about for a GridView as well? Is it any different?

Nicolaj
 
A

Ajak

i don't think it's possible to limit datagrid rows without having to query
all the data.
however, the only way as far as i know is to limit number of records in the
query as suggested by riki.
If you have the query in a stored proc, you can make another copy of it and
set it's limit there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,016
Latest member
TatianaCha

Latest Threads

Top