Set maximum Rows to be displayed in a datagrid

Discussion in 'ASP .Net Datagrid Control' started by Nicolaj, Aug 13, 2006.

  1. Nicolaj

    Nicolaj Guest

    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
    Nicolaj, Aug 13, 2006
    #1
    1. Advertising

  2. Nicolaj

    Nicolaj Guest

    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.

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


    Regards,

    Nicolaj
    Nicolaj, Aug 13, 2006
    #2
    1. Advertising

  3. Nicolaj

    Riki Guest

    Nicolaj wrote:
    > 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;

    --

    Riki
    Riki, Aug 13, 2006
    #3
  4. Nicolaj

    Nicolaj Guest

    Riki wrote:
    > Nicolaj wrote:
    > > 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;
    >


    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
    Nicolaj, Aug 14, 2006
    #4
  5. Nicolaj

    Ajak Guest

    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.


    "Nicolaj" <> wrote in message
    news:...
    > Riki wrote:
    >> Nicolaj wrote:
    >> > 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;
    >>

    >
    > 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
    >
    Ajak, Aug 14, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wh1974
    Replies:
    2
    Views:
    2,934
    wh1974
    Aug 6, 2004
  2. boney
    Replies:
    1
    Views:
    542
  3. Kagu
    Replies:
    0
    Views:
    424
  4. Andrew Chalk

    No. of rows displayed in paged datagrid

    Andrew Chalk, Nov 12, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    112
    Andrew Chalk
    Nov 12, 2005
  5. phanhuyich
    Replies:
    4
    Views:
    245
Loading...

Share This Page