Binding Grid From Query in LightSwitch 2012 - Part 1

Here we will see how to add a query on a table in LightSwitch using Visual Studio 2012.

This article describes how to add a query in a table.

Step 1

Open the Solution Explorer.

Query sol exp.jpg

Step 2

In the Solution Explorer, right-click on the Server and choose "Add Table".

Add table.jpg

Step 3

The table appears.


Step 4

In the Solution Explorer, right-click on the Screens and choose "Add Screen".

Add Screen.jpg

Step 5

The Add New Screen dialog box appears. Select the "Editable Grid Screen" from the Screen Template, under screen information, choose "Employee" under the screen data and provide a name to the Screen and click the "OK" button.


The screen designer appears.

src desi.jpg

Step 6

Press F5 to run the application.


Step 7

Now stop debugging and right-click on the table and choose "Add Query".

Add query.jpg

The Query Screen Designer will open. Right-click on the query and choose "Rename" to rename the query.


Step 8

There are two ways of adding parameters to a Query.

1: Go to "Add Query Element" in the top of the query designer, a drop down list will appear, choose "Add Filter".

Add filter.jpg

2: Another way is, in the query designer, directly click on "Add Filter".

Or Add Filter.jpg

Either way, a new row will be added by which you can add a query.

filter added.jpg

The filter consists of the following 5 columns:

1: The first column consists of two values in a drop down format (in other words where and where not).

where or where not.jpg

2: The second column consists of a list of all the records that belong to a table on which the filter can be applied. The user can select any one field from the given list.


3: The third column consists of the list of all comparison operators. Here the user can also select an operator from the list.

equal operator.jpg

4: The fourth column consists of the query parameter type.


5: The fifth column consists of the query parameter value.


To add a parameter, select parameter under the type of query parameter and select "Add New" in the last column.

Add New.jpg

Once we have selected the "Add New" option, in the parameter section a new row will be added automatically as shown below.

new row in parameter.jpg

Suppose we want to make the parameter optional. To do that first select the parameter option and then go to the property window.


Mark the "IsOptional" checkbox checked.

property win.jpg

Up Next
    Ebook Download
    View all
    View all