How to bind the VIBlend DataGrid for Silverlight to SQL Table?
|
Article Information
|
This article relates to the VIBlend DataGrid for Silverlight. It contains a complete example which illustrates how to bind the DataGrid control to the Customer table of the AdventureWorksLT Database.
|
How To
|
Display SQL Database Table in VIBlend DataGrid for Silverlight
|
Solution
|
To achieve this, follow these steps:
|
1. Create a new Silverlight application named SQLDataBinding
|
2. Create a new DataGrid and Button instances. Set the DataGrid AutoGenerateColumns property to true.
|
|
3. Right-click on the server project and choose Add->New Item, and then choose the LinqToSql Classes.
|
4. Open the Server Explorer (View->Server Explorer) and navigate to the AdventureWorksLT Database (installed with SQL Server 2008 or you can get it from http://sqlserversamples.codeplex.com/). Then open the Tables folder and navigate to the Customer table.
|
|
5. Drag the Customer table onto the DataClasses1.dbml Designer workspace and set the Serilaization mode to Unidirectional by right-clicking on the Designer workspace and using the Property grid.
|
|
6. Create a new WebService. Right-Click on the Web Server project and click the 'Add New Item'. Then navigate to the WebService and click the 'Add' button.
|
7. Open the IService1.cs file and add the GetCustomers method.
|
|
8. Open the Service1.svc.cs file and implement the GetCustomers method.
|
|
9. Add a reference to the Web Service in the Silverlight project. To do that you need to right-click on the references in the Silverlight project and choose the 'Add Service Reference' item. Then add the Service1.svc.
|
10. In the button's Click event handler, create a new instance of the WebService, subscribe to the GetCustomersCompleted event and call the GetCustomersAsync method.
|
|
11. Finally, in the GetCustomersCompleted event handler, bind the DataGrid.
|
|
|