R – GridView sorting doesn’t work when I Enable Caching in Custome Paging and sorting

gridviewobjectdatasourcepagingsorting

I have a GridView that use a stored procedure for custom paging and sorting .
It's OK and works fine (Both paging and sorting) , But the problem is when i Enable Caching in ObjectDataSource like :

 EnableCaching="True"

It properly cache every page that the user visit , But at this case when the user want to sort it raise an error(While that works fine if EnableCaching ="False" :

The data source 'ObjectDataSource1' does not support sorting with IEnumerable data. Automatic sorting is only supported with DataView, DataTable, and DataSet.

what should i do in order sorting works when i Enable caching .

Thank you .

Best Answer

If we have caching enabled, when the select method is executed, the cache is accessed before firing the Selecting event and if the data we're searching is in the cache, the select method returns with the cached data.

So if we're doing any preprocessing (ex:sorting) of the input parameters in the Selecting event caching doesn't work because the cache key created depends only on the select parameters (and its values) and paging values (as caching works with paging). Also keep in mind that caching doesn't work if we have a sort parameter.

Click here to read more

Related Topic