/asp-net-mvc-grid-change-editor-type-based-on-another-editor-value

Change the editor type for a certain field based on the value of another editor in the edit form.

Primary LanguageJavaScriptOtherNOASSERTION

Grid View for ASP.NET MVC - How to change an editor's type based on another editor's value

This example demonstrates how to change the editor type for a certain field based on the value of another editor in the edit form.

Implementation Details

In this example, the type of LastName column editor changes from textbox to combobox when the FirstName editor value equals newperson.

function onTextChanged(s, e) {
    if (s.GetText() == 'newperson') {
        cbEdit.SetVisible(true);
        txtEdit.SetVisible(false);
    } else {
        cbEdit.SetVisible(false);
        txtEdit.SetVisible(true);
    }
}

It is impossible to bind two editors placed on one form to the same field (in this case, their Name property will be equal, which is forbidden). This is why a hidden field is used to store values and transfer them to the server.

function ChangeHiddenValue(s, e) { 
    var hidden = document.getElementById('LastName');
    hidden.value = cbEdit.GetVisible() ? cbEdit.GetText() : txtEdit.GetText();
}

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)