SelectMethod in objectDatasource getting called multiple times with multiple datapagerfield

前端 未结 1 1603
太阳男子
太阳男子 2021-01-16 17:39

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 objectdatas

相关标签:
1条回答
  • 2021-01-16 18:26

    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.

    0 讨论(0)
提交回复
热议问题