Files to look at:

How to implement a simple custom binding scenario for GridView

[Run Online]

This sample demonstrates how to implement a simple custom binding scenario for the GridView extension by handling only sorting and paging operations in the corresponding Action methods.

To learn more on the GridView's custom data binding feature, please refer to the Custom Data Binding help topic.


Note that this sample provides a universal implementation approach - it can be easily adopted and used for every data source object that implements the IQueryable interface.

 

In short, the logic of this custom binding implementation is as follows:


In the GridView's Partial View (Views > Home > GridViewPartial.cshtml), the grid's CustomBindingRouteValuesCollection property is used to define handling actions for sorting and paging operations; the CallbackRouteValues property defines the action to handle all other (standard) grid callbacks.


In the Controller (Controller > HomeController.cs), the specified Action methods are implemented to update a specific grid view model object (GridViewModel that maintains the grid state) with the information of the performed operation (if required). Then, the grid view model's ProcessCustomBinding method is called to delegate a binding implementation to specific model-layer methods pointed by the method's certain parameters.


At the Model layer (Models > CustomBindingModel.cs), the two specified delegates are implemented to populate the grid view mode with the required data. Generally, in the provided implementation of model-level binding delegates, you just need to modify a single code line to point to your particular model object:

        static IQueryable Model { get { return NorthwindDataProvider.GetCustomers(); } }

Finally, the resulting grid view model object is passed from the Controller to the grid's Partial View as a Model. In the Partial View, the grid binds to the Model via the BindToCustomData method.

Note that when implementing the grid's custom data binding, the DevExpressEditorsBinder must be used instead of the default model binder to correctly transfer values from DevExpress editors back to the corresponding data model fields. In this code example, the DevExpressEditorsBinder is assigned to the ModelBinders.Binders.DefaultBinder property within the Global.asax file, thus overriding the default model binder.

 

See Also:
E4398: How to create a master-detail GridView with paging and sorting using Custom Data Binding