Loading Data from ADO.NET Services
The purpose of this tutorial is to show you how to populate a RadGridView with data from an ADO.NET Data Service in two ways:
A straight-forward way - plain method calls.
Using MVVM approach.
This tutorial will use the Northwind database, which can be downloaded from here.
Before proceeding further with this tutorial you need to create a new application and add a RadGridView declaration in your XAML:
Plain Method Calls
Add a reference to your ADO.NET Data Service.
Switch to the code-behind and add a reference to the NorthwindEntities object.
For more information about how to add a reference to an ADO.NET Data Service and how to create a new instance of the exposed entity, take a look at the
Consuming ADO.NET Data Service topic.The gridview control will be populated with all Customers from the Northwind database. Add the following code which will make the initial load of the objects.
Run your demo, the result can be seen on the next image:
Using MVVM Approach
This section will show you how to populate your RadGridView control in a MVVM manner. RadGridView will be bound to a data source object, that has a property Customers. When the control is loaded all customers from the Customers table in the Northwind database are loaded.
- Create a new class named NorthwindDataSource.
Add a reference to your ADO.NET Data Service.
In the NorthwindDataSource class add a reference to an ObservableCollection of Customers.
In the NorthwindDataSource class add a reference to the NorthwindEntities object:
- Add the following code in the constructor of the NorthwindDataSource. It will make the initial load of all Customers from the database:
- Declare the NorthwindDataSource object as a resource in your application.
- Update your RadGridView declaration - set the ItemsSource property.
If you need to define the columns manually take a look at the Defining Columns topic.