This example demonstrates declarative client-side data-binding of RadGrid for ASP.NET AJAX to WCF Web Service and ADO.NET Data Service. All RadGrids have enabled paging/sorting/filtering.
The first RadGrid component is bound to WCF Web Service. You need to point the control to an existing web service and method with following signiture:
<ClientSettings>
<DataBinding SelectMethod="GetDataAndCount" Location="GridWcfService.svc"
SortParameterType="Linq" FilterParameterType="Linq">
</DataBinding>
</ClientSettings>
[OperationContract]
public ResultData GetDataAndCount(int startRowIndex, int maximumRows, string sortExpression, string filterExpression)
where ResultData is custom class that holds data returned from the service to client:
public class ResultData
{
public int Count { get; set; }
public List<Product> Data { get; set; }
}
The second RadGrid is bound to ADO.NET Data Service. You need to point the control to an existing data service and set the following settings:
<ClientSettings>
<DataBinding Location="GridAdoNetDataService.svc" SelectCountMethod="GetCount">
<DataService TableName="Products" />
</DataBinding>
</ClientSettings>
and GetCount method:
[WebGet]
public int GetCount(string where)
{
return String.IsNullOrEmpty(where) ? CurrentDataSource.Products.Count() : CurrentDataSource.Products.Where(where).Count();
}
The third RadGrid is bound to a remote OData service at Odata.org. The setup for OData binding is similar to the above example of ADO.NET Data Service binding:
<ClientSettings>
<DataBinding Location="http://demos.telerik.com/aspnet-ajax/Services/NorthwindWcfService.svc" ResponseType="JSONP">
<DataService TableName="Products" Type="OData" />
</DataBinding>
</ClientSettings>
To have RadGrid setup remote service binding, the ResponseType="JSONP"
property is used to indicate RadGrid will initiate JSONP requests instead of regular JSON requests.
Additionally, to indicate binding to OData services, the DataService.Type
property is set to OData
. This is to differentiate between services using the OData protocol versus the ADO.NET Data Services API prior ot .NET 4.0 (in .NET 4.0 the ADO.NET Data Services conform to the OData protocol). You can find more info on the topic in the RadGrid for ASP.NET AJAX client-side databinding to OData services blog post.