Giter VIP home page Giter VIP logo

asp-net-mvc-grid-cascading-combo-boxes-in-edit-form's Introduction

Grid View for ASP.NET MVC - How to implement cascading combo boxes in the grid's edit form

This example demonstrates how to create cascading combo box editors and use them to edit grid data.

Overview

Follow the steps below to implement cascading combo boxes in the grid's edit form:

  1. Call a column's MVCxGridViewColumn.EditorProperties method to add a combo box editor to the column.

    settings.Columns.Add(c => c.CountryId, country =>{
    	country.Caption = "Country";
    	country.EditorProperties().ComboBox(cs => cs.Assign(ComboBoxPropertiesProvider.Current.CountryComboBoxProperties));
    });
    settings.Columns.Add(c => c.CityId, city =>{
    	city.Caption = "City";
    	city.EditorProperties().ComboBox(cs => cs.Assign(ComboBoxPropertiesProvider.Current.CityComboBoxProperties));
    });
  2. Add a MVCxColumnComboBoxProperties object to specify an editor's settings and call the MVCxColumnComboBoxProperties.BindList method to bind the column to a data source.

    MVCxColumnComboBoxProperties countryComboBoxProperties;
    public MVCxColumnComboBoxProperties CountryComboBoxProperties {
        get {
            if(countryComboBoxProperties == null)
                countryComboBoxProperties = CreateCountryComboBox();
            return countryComboBoxProperties;
        }
    }
    protected MVCxColumnComboBoxProperties CreateCountryComboBox() {
        MVCxColumnComboBoxProperties cs = new MVCxColumnComboBoxProperties();
        cs.CallbackRouteValues = new { Controller = "Home", Action = "ComboBoxCountryPartial" };
        // ...
        cs.ClientSideEvents.SelectedIndexChanged = "CountriesCombo_SelectedIndexChanged";
        cs.BindList(WorldCities.Countries.ToList());
        return cs;
    }
  3. Specify the secondary editor's CallbackRouteValue parameters.

  4. Handle the primary editor's SelectedIndexChanged event. In the handler, call the secondary editor's PerformCallback method to update the editor's data.

    function CountriesCombo_SelectedIndexChanged(s, e) {
        customCallback = true;
        grid.GetEditor('CityId').PerformCallback();
    }
  5. Handle the secondary editor's client-side BeginCallback event and pass the selected value of the secondary editor as a parameter.

    function CitiesCombo_BeginCallback(s, e) {
        e.customArgs['CountryId'] = grid.GetEditor('CountryId').GetValue();
    }
  6. Use the grid's GetComboBoxCallbackResult method to get the result of callback processing.

    public ActionResult ComboBoxCountryPartial(){
        return GridViewExtension.GetComboBoxCallbackResult(ComboBoxPropertiesProvider.Current.CountryComboBoxProperties);
    }
  7. Call the secondary editor's CallbackRouteValues.Action method to populate the editor with values based on the passed parameter.

Files to Review

Documentation

More Examples

asp-net-mvc-grid-cascading-combo-boxes-in-edit-form's People

Contributors

devexpressexamplebot avatar dxbz avatar elenapeskova avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.