ASP.NET 2.0 SelectCountMethod

G

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?

Thanks,

Chris
 
B

Brock Allen

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).
 
A

Andrew Robinson

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
 
G

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.
 
G

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.

Thanks,

Chris (Oldman)
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top