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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.