asp.netsql-serverpaginationrepeatercustompaging

Efficient paging with Repeater, SQL Server and custom Pager


I have just uploaded the following article to codeproject:

http://www.codeproject.com/KB/webforms/efficientpagingrepeater.aspx

Basically it is using Repeater, SQL Server with the ROW_NUMBER() OVER statement and a custom pager.

I would like to extend the pager so that it can be used multiple times on a single page and also allow previous / next buttons. I am unsure how to do that - can anybody provide suggestions / some code modifications?


Solution

  • CP hasn't posted the article yet, so I cannot comment on that. I can say that just about every DAL tool (EF, NH, AR, Massive, Dapper.Net, Simple.Data) all have paging built in. so hooking up paging to a repeater should not be a problem at all.

    If the article is referring to a webforms server control that pages data, I would avoid it at all costs. data access should not be managed by UI components. and using any of the various DAL listed above, it's very simple to access the database using code, instead of drag-n-drop controls.

    to get db paging in place you need 3 inputs and 2 outputs inputs

    1. sql query & parameters
    2. starting point (page or page index)
    3. max # of records (page size)

    outputs

    1. current page of results
    2. total number of records

    using the total number of records and the page size you can calculate the total number of pages.

    var pages = total records / page size + (total records % page size > 0 ? 1 : 0);
    

    with the page of results, current page & total number of pages you can build the UI layout