Skip to main content

How to: Implement Custom Data Binding with Paging and Sorting

  • 2 minutes to read

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, refer to the Custom Data Binding - Overview help topic.

Note that this sample provides a universal implementation approach - it can be easily adopted and used for every custom 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 GridViewSettings.CustomBindingRouteValuesCollection property is used to define handling actions for sorting and paging operations; the GridSettingsBase.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 information on the performed operation (if required). Then, the grid view model’s GridViewModel.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 model-level implementation, you just need to modify a single code line to point to your particular model object that implements the IQueryable interface:

    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 is bound to the Model via the GridViewExtension.BindToCustomData method.

You can see the complete code sample at the following link:

View Example: How to implement a simple custom binding scenario for GridView