Bryan
Bryan

Reputation: 105

Change DevExpress MVC ComboBox selected value based on another combobox value

My code is below. I have 4 comboboxes, all in separate partial views, and I want to change the selected value of the county combobox when I select the judge combobox. The judge combobox has the county in the selection so you have the name or I can look up the county based on the judgeid How do I do that?

...

@model TestCascadeCombobox.Models.CCmaster

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <table>
        <tr>
            <td>
                <div style="padding:5px">
                    @Html.Label("County", "County")
                </div>
            </td>
            <td>
                <div style="padding:5px">
                    @Html.Partial("CountyPartial", Model)
                </div>
            </td>
            <td>
                <div style="padding:5px">
                    @Html.Label("Judge", "Judge")
                </div>
            </td>
            <td>
                <div style="padding:5px">
                    @Html.Partial("JudgePartial", Model)
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div style="padding:5px">
                    @Html.Label("Year", "Year")
                </div>
            </td>
            <td>
                <div style="padding:5px">
                    @Html.Partial("YearPartial", Model)
                </div>
            </td>
            <td>
                <div style="padding:5px">
                    @Html.Label("Month", "Month")
                </div>
            </td>
            <td>
                <div style="padding:5px">
                    @Html.Partial("MonthPartial", Model)
                </div>
            </td>
        </tr>
    </table>
}

Next is the Partial View for the Judge

@model TestCascadeCombobox.Models.CCmaster




@Html.DevExpress().ComboBox(settings =>
{
    settings.Name = "Judge";
    //settings.CallbackRouteValues = new { Controller = "CircuitCaseloads", Action = "JudgePartial"};
    settings.Properties.ValueType = typeof(int);
    settings.Properties.TextField = "FullName";
    settings.Properties.ValueField = "JudgeID";    
    settings.Properties.ClientSideEvents.SelectedIndexChanged = "function(s,e) { County.PerformCallback(); Month.PerformCallback(); }";

}).BindList(Model.judges).Bind(Model.judge).GetHtml()

Upvotes: 0

Views: 1254

Answers (2)

Bryan
Bryan

Reputation: 105

Here is what I did to fix my problem.

function CountyComboBox_EndCallBack(s, e) {  

    s.SetValue(County.cpcountyid);  

}  


settings.Properties.ClientSideEvents.EndCallback = "CountyComboBox_EndCallBack";  
    settings.CustomJSProperties = (s, e) =>  
    {  
        e.Properties["cpcountyid"] = ViewData["countyid"];  
    };

Upvotes: 0

Mikhail
Mikhail

Reputation: 9300

The main idea it to handle the client-side SelectedIndexChanged event of the (judge) ComboBox and update the related (county) ComboBox via a callback. Check out the related MVC ComboBox Extension - How to implement cascaded combo boxes guide to find all the necessary implementation details.

Upvotes: 1

Related Questions