ListBox Paging in Silverlight 4 using DataPager control

Posted by: Suprotim Agarwal , on 3/27/2011, in Category Silverlight 2, 3, 4 and 5
Views: 71806
Abstract: Prior to Silverlight 4, implementing paging in an application would require the developer to create controls, that would allow the user to move from one page to another. With the introduction of DataPager control in Silverlight 4, this task has become much simpler. Let us see how.

Prior to Silverlight 4, implementing paging in an application would require the developer to create controls, that would allow the user to move from one page to another. Check an old article by Malcolm Efficient Paging In Silverlight 2.0 which shows how to create and consume a WCF service in Silverlight 2.0 and use efficient server side paging using LINQ to page through event log data.

With the introduction of DataPager control in Silverlight 4, this task has become much simpler. All you need to do is add the DataPager to your page, configure a few properties and use it with the PagedCollectionView.

The DataPager control is a fully templatable data control that provides a user interface for paging through a collection of data. To provide paging functionality for an IEnumerable collection, you can wrap it in the PagedCollectionView class.

Let us see a demonstration of how to use the DataPager control to page through a ListBox control in Silverlight.

Step 1: Create a Silverlight 4 project. Drag and drop a ListBox and DataPager control from the toolbox to the UI.

Step 2: In the MainPage.xaml.cs, add an Employee class as shown below:

employee class

Step 3: Now create the PagedCollectionView using the Employee class we just created in Step 2, and assign it to the DataContext of the MainPage. Observe how we are providing paging functionality for an IEnumerable collection, by wrapping it in the PagedCollectionView class.

pagedcollectionview

Step 4: The last step is to configure a few properties of the DataPager and ListBox and to specify the view as the Source of these controls

listboxsource

Here the PageSize property of the DataPager controls how many items appear on a single page. You can also use the LoadSize property to control how many items the DataPager will load into memory at one time. The DataPager also includes a DisplayMode property that is used to control the appearance of the DataPager control.

That’s it. Run the application and page through the ListBox.

listbox paging

listbox paging

I hope you liked the article and I thank you for viewing it. The entire source code of this article can be downloaded over here

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce the The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on .NET Standard and the upcoming C# 8.0 too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for ten consecutive times. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.

Get in touch with him on Twitter @suprotimagarwal or at LinkedIn



Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Pratik on Friday, September 9, 2011 1:51 AM
Thanks you very much.it's save my lot of time to search and implemention.
Comment posted by Liviu on Wednesday, November 5, 2014 7:41 AM
Thanks for the tip.

Categories

JOIN OUR COMMUNITY

POPULAR ARTICLES

C# .NET BOOK

C# Book for Building Concepts and Interviews

Tags

JQUERY COOKBOOK

jQuery CookBook