当启用缓存为 true 时,不会为 ObjectDatasource 引发选定的事件
我有一个使用 ODS(ObjectDataSource) 来获取数据的 Gridview 控件。为了获得最佳性能和效率,我关闭了 Gridview 的视图状态(即 EnableViewstate =“false”)。
并且我还在关联的 Objectdatasource 中启用了缓存。这消除了多达 50-60% 的性能优化,因为它消除了数据库往返......礼貌 ODS 缓存
因此,在此之后我陷入了著名的“ODS 排序”问题,但我设法为其发明了一个棘手的解决方案并且工作正常:
下分页,它也工作正常。现在,我需要在 Gridview 顶部显示“总记录:X”。好吧,我部署了以下方法:
protected void ods_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if(e.ReturnValue != null && e.ReturnValue.GetType() == typeof(int))
base.setTotalLabel(lblTotal, e.ReturnValue);
}
不要混淆 - base.setTotalLabel 是我自己的方法,用于设置标签文本与计数。这也工作正常,但问题是 -
每当 ODS 从以下位置获取数据时 它的缓存不会触发 ODS_Selecting 或 ODS_Select 事件。 它们只是被“绕过”,因为它 从缓存中获取数据。这就是当我 刷新总记录失败 数数!
我希望我已经很好地解释了我的问题,这很棘手。我准备为此做任何技巧或肮脏的编码,因为我想维护 ODS 缓存,并且我不能仅仅因为一些偶然的“错误更新”而回滚更改。
请帮忙!
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:
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用,我设置了 CacheKeyDependency,并且每当我想刷新时我都会将其显式设置为新值。如果我想显式刷新,我会在查询字符串中传递 &refresh=1 。
在 .aspx 中 -
在代码隐藏中 -
This worked for me I set the CacheKeyDependency and I explicitly set it to a new value whenever I want to refresh. I pass &refresh=1 in querystring if I want to explicitly refresh.
In .aspx -
In code behind -
我有完全相同的问题吗?
我一直在做的一个解决方案是在 gridview 数据绑定方法中再次调用 select count 方法(通过 BLL)并将其存储在 viewstate var 中,然后使用它来显示记录数。但这会导致两件事:
I have the exact same problem?
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:
我通过在选定事件期间将记录计数存储在会话变量中解决了这个问题:
然后在 Page_Load 中,如果会话变量不为空,我将显示记录计数:
现在,如果数据来自缓存,则 lblRecordCount 将显示记录计数
I solved this by storing the record count in a session variable during the selected event:
Then in Page_Load I display the record count if the session var is not null:
Now lblRecordCount will show the record count if the data comes from the cache or not