locked
How to get automatic next page in cshtml ? RRS feed

  • Question

  • User-1089818190 posted

    Hi all,

    Can I edit to get automatic next page in the following cshtml code : ( Eg: Previouse 2 3 4 5 Next )

    @{
    var db = Database.Open("SmallBakery"); 
    var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
    }

    <html> 
    <body> 
    <h1>Small Bakery Products</h1> 
    <table> 
    <tr>
    <th>Id</th> 
    <th>Product</th> 
    <th>Description</th> 
    <th>Price</th> 
    </tr>
    @foreach(var row in db.Query(selectQueryString))
    {

    <tr> 
    <td>@row.Id</td> 
    <td>@row.Name</td> 
    <td>@row.Description</td> 
    <td style="text-align:right">@row.Price</td> 
    </tr> 
    }
    </table> 
    </body> 
    </html>

    Help me please ? Thanks..

    Saturday, October 25, 2014 2:10 PM

Answers

All replies

  • User-821857111 posted

    You can add your own paging. I cover how to do that in this article: http://www.mikesdotnetting.com/article/150/web-pages-efficient-paging-without-the-webgrid

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, October 25, 2014 4:38 PM
  • User-735851359 posted

    Hello,

    You can use WebGrid Helper:

    @{
    var db = Database.Open("SmallBakery"); 
    var selectQueryString = "SELECT * FROM Product ORDER BY Name"; 
    var grid = new WebGrid(source: selectQueryString, rowsPerPage: 10);
    }
    
    <html> 
    <body>
       @grid.GetHtml()
    </body> 
    </html>

    rowsPerPage specifies how many items will be displayed on each page.

    You can find more information on the following page:

    http://www.asp.net/web-pages/overview/getting-started/introducing-aspnet-web-pages-2/displaying-data

    Good luck..

    Sunday, October 26, 2014 10:33 AM
  • User-735851359 posted

    Hello,

    what is your result?

    Did you try the solutions?

    Saturday, November 1, 2014 4:23 AM
  • User1122679459 posted

    Hi Mike, how would you go about limiting the number of page links shown. I can see you having a large number of them if there is a lot of data?

    Wednesday, November 5, 2014 7:35 AM
  • User-371148474 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 ...

    Wednesday, November 5, 2014 7:58 AM
  • User-1089818190 posted

    Hi ayanmesut,

    Thanks for your help. This way I already learns from you but I want such as Mekis article example... Thank you.

    Thursday, November 6, 2014 7:29 AM