GridView sorting doesn't work when I Enable Caching in Custome Paging and sorting

依然范特西╮ 提交于 2019-12-24 04:55:09

问题


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 .


回答1:


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




回答2:


How about this post -

http://forums.asp.net/p/1509071/3676014.aspx#3676014

I got the lead from the following two URLs:

http://www.codeproject.com/KB/aspnet/GridViewObjectDataSource.aspx http://forums.asp.net/t/1344883.aspx

In both these examples, they've implemented a generic sorting routine which handled the sorting of ODS (Obj Data Source) and with this we're able to set the ODS caching property:

EnableCaching="True"

Any expert opinions?

PS: To boost-up the performance I've the Viewstate disabled in both ODS as well as the GridView using that ODS and Caching on in ODS.




回答3:


Here's my review:

Optimize Pagination & Sorting with ObjectDataSource having EnableCaching = true



来源:https://stackoverflow.com/questions/1974162/gridview-sorting-doesnt-work-when-i-enable-caching-in-custome-paging-and-sortin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!