SelectMethod in objectDatasource getting called multiple times with multiple datapagerfield

眉间皱痕 提交于 2019-12-01 13:33:55

Actually you should be using the OnSelecting event.

What happens is that ObjectDataSource calls the method SelectMethod twice

  1. First time it gets the data.
  2. Next time it gets the count.

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" /> 

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;
      }
}

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

Hope this helps.

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