How to Bind Grid With View in LightSwitch 2012.

This article describes binding of a Grid with a View in LightSwitch 2012.

Procedure for binding a grid with a view in LightSwitch.

Step 1

Open the Solution Explorer for the new project as in the following:

sol exp.jpg

Step 2

Now open the SQL Server Management Studio (SSMS).

database.jpg

Right-click on "DataBase" and choose "New DataBase...".

new db.jpg

Provide a name for the database and click the "OK" button.

Step 3

For creating a Table in the database, right-click on the table and choose "New Table".

new table.jpg

In this way we will create two tables.

Student Table

Student table.jpg

Subject Table

subject table.jpg

Now I will add some data in both the tables.

data student.jpg

data subject.jpg

Step 4

In the application, go to the Solution Explorer and choose "Add Data Source".

Add data source.jpg

The Attach Data Source Wizard Dialog Box appears.

Choose "Database" and click the "Next" Button.

data source wizard.jpg

In the Connection Properties dialog Box, enter the Server Name then select the Authentication Type, after selecting the server name select the database.

connection properties.jpg

Once all the credentials are entered, click on the "Test Connection" button to test the connection. A dialog box will appear, click the "OK" button.

succeed.jpg

Once the connection is tested click the "OK" button to proceed further.

Select the DataBase Object that you want to choose, after selecting the objects click "Finish" button.

database object.jpg

Step 5

Now you will notice that the DataSource will be added to the Solution Explorer.

solution ex1.jpg

Step 6

In order to create a view in the database, right-click on "View" and choose "New View".

New View.jpg

The Add Table dialog box appears from which you can select the table that you want to use in order to create a view.

add table.jpg

Select the data from the table that you want to use in order to create a view and then save the view and provide a name to the view.

choose data.jpg

Step 7

Right-click on Data Source and choose "Update Datasource".

update data source.jpg

The Database Object Dialogbox appears on the screen. Select a view from the Database object and click "Finish" button.

data source object.jpg

After clicking the "Finish" button, a warning pop-up will appear, click the "Continue" button to update the database.

warning.jpg

Step 8

Right-click on Screen and choose "Add Screen".

add src.jpg

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

student editable src.jpg

In the same way we will add another Editable Grid Screen for the View.

src view.jpg

Step 9

Press F5 to run the application
.

out1.jpg

out2.jpg


Similar Articles