Use LINQ Methods to Implement Paging in C#

With the Skip and Take methods in LINQ, paging has become a lot easier.

All we need to do is have a simple logic such as is outlined below. This will provide the paged items.

var pagedItems = theListWithLotsOfItems.Skip ((pageNumber - 1) * pageSize).Take(pageSize);pageNumber(1) and pageSize(10) will provide first 10 items, and pageNumber(2) and pageSize(10) will provide second page data - another 10 items and so on.
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Related Posts