ASP.NET 2.0 SelectCountMethod

Discussion in 'ASP .Net' started by Guest, Nov 10, 2005.

  1. Guest

    Guest Guest

    I noticed that the SelectCountMethod is called on every postback to the
    server when navigating the pages in a GridView. Do you know why this is?

    This is a performance problem since I have to do a query and then have to do
    some manipulation on the entire results to figure out the count (No it isn't
    possile to do it from SQL). I'm thinking I have to stash the count in my
    ObjectDataSource so that I can just hand it back on a post back since it
    never changes from page to page (page in the sense of paging in the
    gridview). The thing is I now have to let the class bound to the
    objectDatasource control know when it is a postback so I can return a cached
    value instead of a recalculating it.

    Is there a better way of doing this instead of linking my data object layer
    to what is happening in the UI?


    Guest, Nov 10, 2005
    1. Advertisements

  2. Guest

    Brock Allen Guest

    With the ObjectDataSource and your data access class, it's entirely up to
    you how to implement those semenatics. If you want your SelectCountMethod
    to go back to the DB every time, then fine. But if it's too expensive then
    you can implement it to cache that data.

    As for the reason it's called every time, this is simply to adjust to any
    updates to the DB since the last time the page was accessed. This has to
    be done since it's possible to have seen a row on the last page, say, then
    switch pages the come back to the last page and then the row is missing,
    presumably because more rows were inserted prior to that last row. (Gosh,
    I hope that made sense).
    Brock Allen, Nov 10, 2005
    1. Advertisements

  3. Oldman,

    Try setting EnableCaching="True" in your Object Data Source. This worked for
    me in a quick little test.

    The ODS is pretty efficient with it queries assuming your underlying data
    access is efficient.

    Andrew Robinson, Nov 10, 2005
  4. Guest

    Guest Guest

    Good point on updates.
    I'm a little confused though how to cache the data from within the data
    access class. You don't have access to the Page's cache, unless you pass it
    in or set it (is that the only way?) and if you put it in a static variable
    then all threads will share it and that won't work.

    Thanks for you response though. That cleared up why it is called each time.
    Guest, Nov 10, 2005
  5. Guest

    Guest Guest

    Thanks for your response.
    I don't think I can enable caching. If I do won't it use the same results
    each time.
    My data access object only returns the results for the current page being
    shown. I need to get a new set of records for the next page when the user
    clicks to see the next page.


    Chris (Oldman)
    Guest, Nov 10, 2005
  6. Guest

    Brock Allen Guest

    HttpContext.Current.Cache or build your own.
    Brock Allen, Nov 10, 2005
  7. Guest

    Guest Guest

    Duh. I knew there must be a general way of getting it.

    Guest, Nov 10, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.