This example demonstrates how to use declarative client-side data-binding.
RadGrid declarative client-side data-binding is very similar to
ObjectDataSource
data-binding. You need to specify
SelectMethod and
SelectCountMethod
(if needed) along with
Location property and the grid will automatically invoke
the specified method as
PageMethod or
WebService method:
...
<ClientSettings>
<DataBinding Location="~/Grid/Examples/Client/DeclarativeDataBinding/WebService.asmx"
SelectMethod="GetData" SelectCountMethod="GetCount" />
</ClientSettings>
...
Important: These methods should be marked with
WebMethod attribute! Example:
[WebMethod(EnableSession=true)]
public List<MyBusinessObject> GetData(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression)
{
...
}
In the ClientSettings.DataBinding section you can also specify the following properties:
- StartRowIndexParameterName - default is "startRowIndex"
- MaximumRowsIndexParameterName - default is "maximumRows"
- SortParameterName - default is "sortExpression"
- FilterParameterName - default is "filterExpression"
Important: By default RadGrid will expect SelectMethod with four arguments with the following
names and types:
- int startRowIndex
- int maximumRows
- List<GridSortExpression> sortExpression
- List<GridFilterExpression> filterExpression
and SelectCountMethod with no arguments!
To change values on the fly of any of the grid declarative client-side data-binding properties you
can use the
OnDataBinding client-side event:
...
<ClientEvents OnDataBinding="RadGrid1_DataBinding" />
...
Please refer to the JavaScript code in this demo for more info.
To optimize even more the grid client-side data binding you can get both data and total items count in a single request.
Example:
...
[WebMethod(EnableSession = true)]
public Dictionary<string, object> GetDataAndCount(int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression, List<GridFilterExpression> filterExpression)
{
Dictionary<string, object> data = new Dictionary<string, object>();
data.Add("Data", GetData(startRowIndex, maximumRows, sortExpression, filterExpression));
data.Add("Count", (int)Session["Count"]);
return data;
}
...
The grid will check automatically for "data" and "count" and will not execute a second request!