Binding to ADO.NET Data Service
The purpose of this tutorial is to show you how to populate a RadComboBox
with data from an ADO.NET Data Service in two ways:
This tutorial uses the Northwind database.
Before proceeding further with this tutorial you need to create a new application and a RadComboBox
declaration in your XAML.
Using Plain Methods Call in the Code-Behind
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 ComboBoxs control will be populated with all Products from the Northwind database. In the drop-down list the
ProductName
and theUnitPrice
properties will be displayed. Add the following code which will make the initial load of the objects. -
You need to declare a custom DataTemplate to determine how the items in the drop-down will look like. Add the following DataTemplate declaration in your XAML resources.
-
Find your RadComboBox declaration and set the just declared DataTemplate to its ItemTemplate property.
The end result with the data fetched from the service
Using MVVM Approach
This section will show you how to populate your RadComboBox
control in a MVVM manner. The ComboBox will be bound to a data source object, that has a property Products
. When the control is loaded all products from the Products table in the Northwind database are loaded asynchronously.
-
Create a new class named
NorthwindDataSource
. Add a reference to your ADO.NET Data Service.
In the
NorthwindDataSource
class add a reference to anObservableCollection
ofProduct
.-
In the
NorthwindDataSource
class add a reference to theNorthwindEntities
object: -
Add the following code in the constructor of the
NorthwindDataSource
. It will make the initial load of all Products from the database: -
Declare the
NorthwindDataSource
object as a resource in your application. -
Declare a custom
DataTemplate
to determine how the items in the drop-down will look like. -
Update your
RadComboBox
declaration - set theItemsSource
andItemTemplate
properties.
The end result with the data fetched from the service