Search code examples
c#asp.netpaginationrepeater

How to paging using Repeater Control?


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.


Solution

  • 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