SelectMethod ObjectDataSource控件中获取调用多个datapagerfield多次 [英] SelectMethod in objectDatasource getting called multiple times with multiple datapagerfield

查看:159
本文介绍了SelectMethod ObjectDataSource控件中获取调用多个datapagerfield多次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以这里的设置。我建立一个网页,有一个列表视图,一个DataPager的,和3 datapagerfield(2×下一页previousPagerField,1个NumericPagerField)和ObjectDataSource控件潮这一切在一起。

Ok, so here is the setup. I am building a page that has a listview, a datapager, and 3 datapagerfield (2 x NextPreviousPagerField, 1 x NumericPagerField), and a objectdatasource to tide all of this together.

这是所有工作正常,直到我把一个断点到在objectdatsource控制指定的SelectMethod。这似乎是对每个datapagerfield控制,它被调用selectme​​thod和selectcount方法。因此,只要用户分页,它调用数据库的6倍,而不是2(我没有缓存打开ATM)。如果我删除一个datapagerfield,它会删除2调用。

It was all working fine until I put a breakpoint into the SelectMethod specified in the objectdatsource control. It seems like that for each datapagerfield control, it is calling the selectmethod and selectcount method. Hence, whenever a user paged, it calls the database 6 times instead of 2 (I don't have caching turned on atm). If I remove one datapagerfield, it will remove 2 calls.

现在,这是建立在VS2008 asp.net 3.5 SP1。当我复制相同的code文件到asp.net 4.0 VS2010的解决方案,它复制调用似乎消失了。

Now this is build in asp.net 3.5 SP1 in VS2008. When I copied the same code files to a asp.net 4.0 VS2010 solution, it duplicate call seems to be gone.

这是一个错误的asp.net 3.5 SP1?

Is this a bug in asp.net 3.5 SP1?

在此先感谢

推荐答案

其实你应该使用OnSelecting事件。

Actually you should be using the OnSelecting event.

什么情况是,ObjectDataSource控件调用该方法SelectMethod的两次

What happens is that ObjectDataSource calls the method SelectMethod twice


  1. 它获得的数据第一次。

  2. 下一次它获得的计数。

所以我认为你必须实现OnSelecting事件

So I think you have to implement the OnSelecting event

<asp:ObjectDataSource ID="ODS" runat="server" SelectMethod="GetList" SelectCountMethod="GetListCount" 
    OnSelecting="ods_Selecting">
    TypeName="Website.Test" EnablePaging="true" /> 

,然后取消该事件时,将ObjectDataSource尝试调用计数方法。

and then cancel the event when the ObjectDataSource tries to call the count method.

 protected void ods_Selecting(object sender,
                ObjectDataSourceSelectingEventArgs e)
 {
      if (e.ExecutingSelectCount)
      {
           //Cancel the event   
           return;
      }
}

您可以使用下面的链接,以便另一个数据库调用没有作出获取计数。
http://www.unboxedsolutions.com/sean/archive/2005 /12/28/818.aspx

You can use the link below so that another db call is not made to fetch the count. http://www.unboxedsolutions.com/sean/archive/2005/12/28/818.aspx

希望这有助于。

这篇关于SelectMethod ObjectDataSource控件中获取调用多个datapagerfield多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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