Searching Multiple Parameters in LightSwitch 2012 - Part 2

In my previous article I described how to create tables, establish relationships and add screens (http://www.c-sharpcorner.com/uploadfile/18ddf7/searching-multiple-parameters-in-lightswitch-2012-part-1/)

This article describes how to add a query for a table and add a data item as well as add a button.

Step 1

Right-click on the Student Table and choose "Add Query".

add query.jpg

Step 2

The Query designer appears. In that add the filter by providing the information and  here I have set the name to "StudentFilter".

query added.jpg

Step 3

To add the query to the editable grid screen, go to the menu bar and click on "Add Data Item".

Add data item.jpg

The Add Data Item dialog box appears. In that choose the "Query Radio Button" and then select the StudentFilter option and provide a name.

add data item dialog.jpg

Delete the existing Grid from the screen.

data item delete.jpg

And drag the FilterStudent query to the Screen. Now the screen designer will look like:

drag filterstudent.jpg

Step 4

Now we will add two data items.

One is the StuNameParam.

stu name param.jpg

The other one is the BranchParam.

branchparam.jpg

As we click OK these data items will be added to the Screen Designer.

dataitems.jpg

Step 5

To add a Model Window, we first need to click on the "Add" and then select a new group from the drop down list.

New group.jpg

Now click on the "Row Layout" dropdown list and choose the "Modal Window" option.

modal window.jpg

After adding the Modal Window, drag both data items (StuNameParam and BranchParam).

drag both data items.jpg

Step 6

We will also add two buttons, one to open the window and the other to close the window.

new button.jpg

add button.jpg

The open window button and 
close window button will be added.

close window.jpg

Right-click on the buttons and choose "Edit Execute Method" for both buttons.

edit execute button.jpg
The Edit Execute Method for the close button is shown in the following figure:

edit exexute close.jpg

The code editor appears; in it provide the information for both the buttons.

using System;

using System.Linq;

using System.IO;

using System.IO.IsolatedStorage;

using System.Collections.Generic;

using Microsoft.LightSwitch;

using Microsoft.LightSwitch.Framework.Client;

using Microsoft.LightSwitch.Presentation;

using Microsoft.LightSwitch.Presentation.Extensions;

namespace LightSwitchApplication

{

    public partial class EditableStudentsGrid

    {

        partial void OpenWindow_Execute()

        {

            // Write your code here.

            this.OpenModalWindow("Group");

        }

 

        partial void CloseWindow_Execute()

        {

            // Write your code here.

            this.CloseModalWindow("Group");

        }

    }

}


Step 7

To bind the Query Parameter with the data item, first of all click on the "Name" for the "Query Parameter".

Name.jpg

Now go to the property window, in the parameter Binding TextBox, write the parameter Name (StuNameParam).

prop1.jpg

The query parameter will be bound with the data item.

Relation shown.jpg

In the same way we will establish the binding between Id Query Parameter and BranchParam Id.

prop2.jpg

The binding will be a shown below.

Relation shown 1.jpg

Step 8

Press F5 to run the application.

output1.jpg

Now click on the open button and add an Employee Name. We get the output as in the following:

output2.jpg

Finally we get:

final output.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all