当在自定义分页和排序中启用缓存时,GridView排序不起作用 [英] GridView sorting doesn't work when I Enable Caching in Custome Paging and sorting

查看:154
本文介绍了当在自定义分页和排序中启用缓存时,GridView排序不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用存储过程进行自定义分页和排序的GridView。

这是正常的,工作正常(分页和排序),但问题是,当我在ObjectDataSource中启用缓存就像:

 EnableCaching =True

用户访问,但在这种情况下,当用户想排序会引发错误(虽然这工作正常,如果EnableCaching =False:

 数据源'ObjectDataSource1'不支持使用IEnumerable数据进行排序,只有DataView,DataTable和DataSet支持自动排序

当我启用缓存时,我应该如何排序。



谢谢。

解决方案

如果我们启用了缓存,当执行select方法时,在选择事件之前访问缓存,并且如果我们搜索的数据是在缓存中,
select方法返回缓存数据。



因此,如果我们在选择事件中对输入参数进行任何预处理(例如:排序),缓存不起作用,因为创建的缓存键只依赖于select参数(及其值)和分页值(as缓存与分页一起工作)。另外请记住,如果我们有一个排序参数,缓存不起作用。



点击这里阅读更多


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 .

解决方案

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

这篇关于当在自定义分页和排序中启用缓存时,GridView排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆