Blogs

The Progress Bar - DevExpress XPF Blog

Silverlight Grid Control – Data Binding using RIA Services

     

As we near the release of version 2010.2 of DXperience, I’m going to work on bringing you some training material in the form of blog posts and videos to help you get started with using the new products and features that make up our Silverlight and WPF product lines.

First one in line is the new Data Grid Control for Silverlight. With all things grid related, the most important first step is of course, you guessed it, binding to data. A grid can be populated with data through different sources, including automatic data generated at runtime, static data, or database tables. In this tutorial we’ll take a look at how to bind the new DXGrid control for Silverlight to a local SQL Server 2008 R2 Express database using WCF RIA Services.

Note: This examples assumes the availability of a local SQL Server Express instance (“.\SQLEXPRESS”).

Video

Video_DevExpress_Silverlight_Grid_Bind_RIA

Step-by-Step Tutorial

So let’s get started... the first step would be to create a new Silverlight Application Project and enable WCF RIA Services.

New_Silverlight_Project

Next step would be to create a new Entity Data Model in the ASP.NET project that’s being used to host the Silverlight application.Select to generate the model from database, and from the desired database server, select the table that you’d like to use to populate the grid control. In this case, it’s the “Product” table from my sample database.

Entity_Data_Model

Make sure you re-build the solution before proceeding further. Create a Domain Service Class and add it to the ASP.NET project. You’ll be asked to select the data contexts and the entities to be used in this domain service.

New_Domain_Service_Class

Once the class has been created, switch to the Silverlight designer and add a new DevExpress GridControl to the application. Set the AutoPopulateColumns property to True so that columns are automatically created based on the available fields in the data source. Then switch to code view and use the following C# code to bind the grid to data:

...
using System.ServiceModel.DomainServices.Client;
using DXGridSL.Web;
...
 
private ProductContext _productContext = new ProductContext();
public MainPage() {
    InitializeComponent();
    LoadOperation<Products> loadOperation = _productContext.Load(_productContext.GetProductsQuery());
    gridControl1.DataSource = loadOperation.Entities;
}

And that’s it! Run the Silverlight application and the grid is bound to the SQL Server database and populated with data.

Published Nov 17 2010, 09:40 AM by Emil Mesropian (DevExpress)
Bookmark and Share

Comments

 

Chris Walsh [DX-Squad] said:

Great sample Emil.  Would be better showing a simple CRUD one.  If you're too busy, I'll happily do one.  Let me know.

November 18, 2010 2:14 AM
 

Emil Mesropian (DevExpress) said:

Hi Chris,

Check your PM. :-)

November 18, 2010 2:27 AM
 

The Progress Bar - DevExpress XPF Blog said:

I have covered data binding the Silverlight Grid Control using WCF RIA Services in the past, but have

January 28, 2011 6:47 PM
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.