0

Can you tell me how can I use pagination in a WebForms Application for a Repeater Control, I need to have a link for back page, next page and also the numbers for each page, ex.

<back>1,2,3,4....n<next>.

What is the best way to do that? I don't want to use the PagedDataSource because I have a lot of data in my DB, so I want to do a call to my DB for each page without select all items at first select.

Anton Belev
  • 11,963
  • 22
  • 70
  • 111
ezechiele2517
  • 375
  • 1
  • 5
  • 19

1 Answers1

3

Since you don't want to use PagedDataSource I would recommend you using stored procedure for your paging. You'll can pass paging details like pageIndex, pageSize, sortBy, sortDirection (ascending/descending) to your stored procedure and then you will have only the data you need for the current page returned, which data you can use to supply your repeater under the form of DataTable or List<MyDataClass>.

For the paging controls you can use a drop down control, for which you can return the total number of rows (before applying paging) along with your stored procedure, so that you can fill the drop down with the number 1,2,3... and so on. Probably you may need to save the current pageIndex in a hidden field, which you will update after click on btnBack or btnNext, or OnSelectedIndexChanged event of your drop down list.

I'm just describing the general picture of my idea and I'll refer to the following links for code snippets that you can use to get started:

Hope this information is enough to get you started. Also there may be some better programming practice, since I'm not that experienced this is what I can recommend. If someone have better suggestions, please comment below.

Anton

Community
  • 1
  • 1
Anton Belev
  • 11,963
  • 22
  • 70
  • 111
  • Nice, I would also add that if using EF you can always count with Skip() and Take() – Gonzix Aug 31 '13 at 14:01
  • Thanks for your reply, I saw the first link you posted and isn't very clear, can you link me others links about paging using stored procedure with also C# example code? I can't find something similar that. – ezechiele2517 Aug 31 '13 at 14:52
  • @ezechiele2517 Have a look at this post, may be the stored procedure [here](http://stackoverflow.com/a/8938957/1479895) is a bit simpler. Also [here](http://basquang.wordpress.com/2011/03/18/stored-procedures-paging-solution-in-asp-net-mvc-2/) extensive solution that I didn't want to post, because it may confuse you. The C# part should be when you are calling the stored procedure (just like a method if you are using Entity Framework) and the taking back the results as a DataTable probably. – Anton Belev Aug 31 '13 at 15:15
  • Also may be this is helpful - [How to execute a stored procedure within C# program](http://stackoverflow.com/q/1260952/1479895) – Anton Belev Aug 31 '13 at 15:18
  • I also found this solution: http://www.aspsnippets.com/Articles/Implement-Paging-in-Repeater-control-in-ASPNet.aspx but I need to customize the paginator to show something like that: 1,2,3,...(with dots) can you help me to do that? – ezechiele2517 Aug 31 '13 at 15:32