How does pagination work in ASP.NET(Using VB.NET)?

前端 未结 2 1890
时光说笑
时光说笑 2021-01-26 17:05

I know how to create and populate a datatable, which i have already done. Now, I simply want to display the datatable on a webform, but I also want to know how to paginate and

相关标签:
2条回答
  • 2021-01-26 17:52

    Ideal pagination is done at database level. For that you create a SP which might take two parameters. One would be the no. of records you want to show on each page and another parameter would no. of page that your user is on.

    For example - if your user is on page 1 and records per page is 20, then retrieve records from your db where row id is from 1 to 20. if user wants to see page 3 then retrieve row 41 to 60. If you do not have uniqueidentifier in your SQL table then you would have to use inner query with the help of ROW_NUMBER() function. Following is a link to paging using SQL Server ROW_NUMBER() function.

    http://www.davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx

    Along side of this logic you can also combine sorting. That could be a third parameter to your SP. You can first sort your data in any way and then take a proper page out.

    0 讨论(0)
  • 2021-01-26 17:53

    First you have to store your data into the session object/ viewstate /cache

    Then generate table/ div according to your requirement and use loop for no. of records you want to display on screen * current page no +1.(current page no you have to store in viewsate or in hidden field)

    For sorting use link on header (use table header with link) then for sorting use Linq. (after sorting data you have to replace your session object/ viewstate /cache object ) You can generate header using column’s name

    0 讨论(0)
提交回复
热议问题