DataPager slow loading

248 Views Asked by At

I'm using a DataPager to add pagination to my ListView. On PageLoad, a search is performed using a query string, and it then adds the results to DataSet that I use to populate the ListView.

The DataPager itself is very basic, all I use is this:

<asp:DataPager ID="ListViewPager" PagedControlID="listViewResults" PageSize="10" runat="server" QueryStringField="page">
  <Fields>
    <asp:NextPreviousPagerField ButtonType="Link" PreviousPageText="Previous" ShowFirstPageButton="false" ShowNextPageButton="false" ShowPreviousPageButton="true" />
    <asp:NumericPagerField ButtonType="Link" />
    <asp:NextPreviousPagerField ButtonType="Link" NextPageText="Next" ShowLastPageButton="false" ShowNextPageButton="true" ShowPreviousPageButton="false" />
  </Fields>
</asp:DataPager>

However, when switching between pages, the results load extremely slowly. Seeing that the search itself is performed on PageLoad (if querystring != null), does it perform that search all over again whenever I go to a new page? If so, is there a better way to handle this so the pages load faster?

1

There are 1 best solutions below

0
Nikola Bogdanović On

Page_Load runs on every postback, so you should use if(!PostBack && querystring != null). Also, paginate your data directly in the DB, not in the code - it's incomparably faster.