6.13. Display Collection Data Using Paging

Problem

You need to segment data from a collection into pages.

Solution

Create a standard query that uses both the Skip and Take clauses to segment the data into appropriately sized pages, and then execute the query in a loop, changing the parameters used with Skip and Take to retrieve and display each page.

How It Works

It is common to divide large amounts of data into manageable chunks, or pages. This is accomplished with LINQ by using a combination of the Skip and Take clauses.

The Skip clause forces the query to skip the specified number of elements, starting from the beginning of the data source. The following example would skip the first three elements of the books collection and then return the ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.