locked
Re: Efficient Paging without the Webgrid RRS feed

  • Question

  • User-371148474 posted

    Mikesdotnetting tutorial on the above did great...

    http://www.mikesdotnetting.com/Article/150/Web-Pages-Efficient-Paging-Without-The-WebGrid

    I was able to efficiently page select query result according to the number per page am interested in.

    The problem is this, After implementing the code; lets say I have a tablerecord of 500 rows and i divide it into 10 rows per page, I have 49 hidden rows.. but the script in the tutorial list out the whole 1-50 because of the 

     for (var i = 1; i < totalPages + 1; i++) statement.. How can I have the 50 paging take a form of 1,2,3,4,5..Next,Last where last is the 50th page instead of having 1,2,3,4,5,6,7,8.....50
    
    Sunday, June 8, 2014 9:35 AM

Answers

  • User1713851783 posted

    Something like this could make the work:

        <a href="/Paging/1">First</a>
        @{
            var startingPage = 1;
            if (totalPages >= 5) 
            {
                if((page - 2) > 0 && (page + 2) <= totalPages)
                {
                    startingPage = page - 2;
                } else if ((page + 2) > totalPages)
                {
                    startingPage = totalPages - 4;
                }
            }
            for (var i = startingPage; i <= startingPage + 4 && i <= totalPages; i++){
                <a href="/Paging/@i">@i</a>
            }
        }
        <a href="/Paging/@totalPages">Last</a>

    Maybe the code could be optimized ...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 8, 2014 11:18 AM