locked
Selected event not raised for ObjectDatasource when enable-caching is true RRS feed

  • Question

  • User-1186378382 posted

    I've a Gridview control using an ODS(ObjectDataSource) to fetch data. For the best performance and efficiency, I've turned-off the view state of Gridview (i.e. EnableViewstate = "false".

    And I've also enabled caching in the associated Objectdatasource. This eliminates as much as 50-60% performance optimization because it eliminates the DB round-trip .. courtesy ODS Caching.

    So, after this I got stuck into the famous "ODS sorting" issue but I managed to invent a tricky solution for it and its working fine:

    http://stackoverflow.com/questions/2255269/optimize-pagination-sorting-with-objectdatasource-having-enablecaching-true

    Next pagination, it is also working fine. Now, I need to display "Total records: X" at the top of the Gridview. Well, I deployed the following method:

    protected void ods_Selected(object sender, ObjectDataSourceStatusEventArgs e)
            {
                if(e.ReturnValue != null && e.ReturnValue.GetType() == typeof(int))
                    base.setTotalLabel(lblTotal, e.ReturnValue);
            }
    

    Don't confuse - base.setTotalLabel is my own method to set the label text with the count. This is also working fine but the issue is that -

    Whenever, the ODS fetches data from its Cache it won't trigger the ODS_Selecting or ODS_Select events. They are simply "by-passed" because it takes data from cache. This is when I fail to refresh the Total records count!

    I hope I've explained my problem good, this is tricky. I'm ready to do any trick or dirty coding for this because I want to maintain the ODS-caching and I can't rollback changes just because of a few incidental "mis-updates".

    Pls help!

    Friday, January 14, 2011 8:15 AM

Answers

  • User3866881 posted

    If you want to get the total number of some columns together. To do this will be your best choice:

    using (SqlCommand cmd = new SqlCommand("select sum(fieldname) from xxx", new SqlConnection("……")))

    {

        GridView.XXX = cmd.ExecuteScaler().ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 16, 2011 9:55 PM

All replies

  • User-1186378382 posted

    A solution I have been doing is to call the select count method again (via BLL) in the gridview databinding method and storing this in a viewstate var then using it to display the number of records. But this leads to two things:

    • another call to the DB count sp (defeats caching purpose)
    • conflict of presentation i.e. number of cached records displayed may not match the actual number(which is up-to-date)

    Any Help would be greatly appreciated.

    Thanks

    Friday, January 14, 2011 8:27 AM
  • User2060565753 posted

    Whenever, the ODS fetches data from its Cache it won't trigger the ODS_Selecting or ODS_Select events

     

    hope this helps

    http://stackoverflow.com/questions/2993771/cached-objectdatasource-not-firing-select-event-even-cache-dependecy-removed 

    Friday, January 14, 2011 8:30 AM
  • User-1186378382 posted

    Yes I realise this. I am not seeking to cache per user nor do I want to invalidate the cache on postback.

    My ods has an absolute expiration and I merely want to display the number of records returned from the ods 'selectcountmethod' whether from the ods db call or ods cache call.

    Friday, January 14, 2011 8:41 AM
  • User3866881 posted

    If you want to get the total number of some columns together. To do this will be your best choice:

    using (SqlCommand cmd = new SqlCommand("select sum(fieldname) from xxx", new SqlConnection("……")))

    {

        GridView.XXX = cmd.ExecuteScaler().ToString();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, January 16, 2011 9:55 PM