Skip to content

DevExpress-Examples/asp-net-mvc-grid-combobox-column-in-callback-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET MVC - How to use a combo box column in callback mode

This example demonstrates how to create a column editor, bind it to a data source, and configure editor callback requirements.

ComboBox column in callback mode

Overview

Use the MVCxGridViewColumn.EditorProperties method to define an editor at a column level.

settings.Columns.Add(columnCountry => {
    columnCountry.Caption = "CountryID";
    columnCountry.FieldName = "CountryID";
    columnCountry.ColumnType = MVCxGridViewColumnType.ComboBox;
    columnCountry.EditorProperties().ComboBox(p => {
        p.CallbackRouteValues = new { Controller = "Home", Action = "CountryComboBox" };
        p.ValueField = "CountryID";
        p.TextField = "CountryName";
        p.ValueType = typeof(int);
        p.CallbackPageSize = 20;
        p.DropDownStyle = DropDownStyle.DropDown;
        p.BindList(E4425.Models.DataProvider.GetCountries());
    });
});

Use the MVCxColumnComboBoxProperties class to specify editor settings. Call the BindList method to bind the column to a data source.

public static MVCxColumnComboBoxProperties CreateComboBoxColumnProperties() {
    MVCxColumnComboBoxProperties p = new MVCxColumnComboBoxProperties();
    p.CallbackRouteValues = new { Controller = "Home", Action = "CountryComboBox" };
    p.ValueField = "CountryID";
    p.TextField = "CountryName";
    p.ValueType = typeof(int);
    p.CallbackPageSize = 20;
    p.DropDownStyle = DropDownStyle.DropDown;
    p.BindList(E4425.Models.DataProvider.GetCountries());
    return p;
}

Call the GetComboBoxCallbackResult method to handle the editor's callback on the server.

public ActionResult CountryComboBox() {
    MVCxColumnComboBoxProperties p = E4425.Helpers.CallbackComboBoxHelper.CreateComboBoxColumnProperties();
    return GridViewExtension.GetComboBoxCallbackResult(p);
}

Files to Review

Documentation