LightSwitch: Implementing Custom Paging with Search Screens That Use Custom Controls
One great benefit of Visual Studio LightSwitch is that search screens and editable grid screens implement a paging mechanism that optimizes the loading of large collections of entities and that allows browsing records in the collection easily. Figure 1 shows an example of built-in paging, which is generated automatically and without writing a single line of code.
By default, LightSwitch returns 45 data items per page, but you can change this number (or completely disable paging) by selecting the data collection in the screen designer and then opening the Properties window. As you may know, LightSwitch extensibility allows replacing built-in controls with custom controls that often extend functionalities of the predefined applications' shell. For instance, you can replace the built-in Data Grid with a more sophisticated version.
Using custom controls also removes the built-in search box and paging mechanisms, which could be a potential limitation, but you can still implement your paging mechanism with a limited effort.
In this article, I'll show you how to replace the default Data Grid control with the RadGridView control from Telerik, a well-known partner of Microsoft. A trial version is available for download.
Creating the Sample Project
Once you've downloaded and installed the Silverlight controls from Telerik, which include the RadGridView control, create a new LightSwitch application. To make things easier, the Northwind sample database is used as an external data source.
Follow these steps:
- In the LightSwitch designer, click Attach to External Data Source.
- Select the Database option.
- Establish a connection to the Northwind database.
- Select the Customers table.
- Once the table is imported into a new entity in LightSwitch, add a new screen of type Editable Grid based on the Customers table.