Dyanmically changing the value of a DropDownList control inside of the Edit Template of a ListView control

3 posts, 0 answers
  1. Scott
    Scott avatar
    5 posts
    Member since:
    Jan 2013

    Posted 05 Mar 2014 Link to this post

    I have a DropDownList control in the Edit template of a ListView control and it is passing values to my controller instance correctly if the user selects a value from the DropDownList and then presses the "k-update-button".

    Also , I have code that dynamically changes the value of the DropDownList control if the value of another DropDownList control is changed. I am using this statement to change the DropDownList control value:


    The above line works correctly and the UI successfully displays the correct DropDownList option on the screen. However, when pressing the "k-update-button", the dynamically selected value is not passed back to the controller during MVC binding. It is a null value.

    Again, my the value binding works if the user selects a value, but it does not work if I dynamically select a value using JavaScript/jQuery. 

    Just wanted to see if this is a known issue and/or if there is a work-around. 

    I have also tried getting the template data via the "Data" method in conjunction with the DataScource Create event but I ran into the same problem here as well. My ListView is defined as:

                                    .Events(events => events
                                    .DataSource(dataSource => dataSource                                   
                                        .Model(model =>
                                                model.Id(a => a.Id);
                                                model.Field(f => f.AdjustmentId);
                                                model.Field(f => f.AdjustmentType);
                                                model.Field(f => f.Description);
                                                model.Field(f => f.ValidationType);
                                                model.Field(f => f.IncreaseDecrease);
                                                model.Field(f => f.Percent);
                                                model.Field(f => f.Amount);
                                        .Create(create => create.Action("CreateAdjustmentForLineItem", "Intake").Data("GetLineItemKeys"))
                                        .Read(read => read.Action("GetAdjustmentsForLineItem", "Intake").Data("GetLineItemKeys"))
                                        .Update(update => update.Action("UpdateAdjustmentForLineItem", "Intake").Data("GetLineItemKeys"))
                                        //Destroy(Delete) handled by Remove event above
                                        .Events(events => events
                                @Html.ValidationMessageFor(model => model.LineItems.LineItemsDetail.Adjustments)

    My Edit Template appears as: 

    @model InvSubModule.WebApp.Areas.Submission.Models.LineItems.AdjustmentsListViewModel

    @using System.Globalization;
    @using System.Web.Mvc.Html
    @using Kendo.Mvc.UI
    @using InvSubModule.Infrastructure.Localization

    <div class="lineItemsAdjustmentView k-widget">
        <div class="lineItemsAdjustmentButtons">
            <div><a class="k-button k-button-icontext k-update-button" href="\\#"><span title='@ResourceManager.GetString("Save")' class="k-icon k-update"></span></a></div>
            <div><a class="k-button k-button-icontext k-cancel-button" href="\\#"><span title='@ResourceManager.GetString("Cancel")' class="k-icon k-cancel"></span></a></div>
            <dt><label class="displayLabel">*@ResourceManager.GetString("LineItems_Adjustments_AdjustmentType")</label></dt> 
                @(Html.Kendo().DropDownListFor(model => model.AdjustmentType)
                        .OptionLabel(" ")
                        .BindTo(new SelectList(Model.AdjustmentTypes, "AdjustmentType", "AdjustmentTypeAnswer"))    
                        .Events(e =>
                @Html.ValidationMessageFor(model => model.AdjustmentType)
            <dt><label class="displayLabel">@ResourceManager.GetString("LineItems_Adjustments_Description")</label></dt>
                @Html.TextBoxFor(model => model.Description, "", new { @id = "Description", @class = "k-input k-textbox k-state-disabled", @disabled="disabled" })
                @Html.ValidationMessageFor(model => model.Description)
            <dt><label class="displayLabel">*@ResourceManager.GetString("LineItems_Adjustments_ValidationType")</label></dt>  
                @(Html.Kendo().DropDownListFor(model => model.ValidationType)
                        .OptionLabel(" ")
                        .BindTo(new SelectList(Model.ValidationTypes, "ValidationType", "ValidationTypeAnswer"))
                        .Events(e =>
                @Html.ValidationMessageFor(model => model.ValidationType)
            <dt><label class="displayLabel">*@ResourceManager.GetString("LineItems_Adjustments_IncreaseDecrease")</label></dt>  
                @Html.RadioButtonFor(model => model.IncreaseDecrease, "Increase")
                @Html.RadioButtonFor(model => model.IncreaseDecrease, "Decrease")                        
                @Html.ValidationMessageFor(model => model.IncreaseDecrease)
                <label id="lblAmount" class="displayLabel">*@ResourceManager.GetString("LineItems_Adjustments_Amount")</label>
                <label id="lblPercent" class="displayLabel" style="display:none;">*@ResourceManager.GetString("LineItems_Adjustments_Percent")</label>
                @(Html.Kendo().NumericTextBoxFor<decimal>(model => model.Amount)
                @Html.ValidationMessageFor(model => model.Amount)
                @(Html.Kendo().NumericTextBoxFor<decimal>(model => model.Percent)
                @Html.ValidationMessageFor(model => model.Percent)

    Thanks for your time,

  2. Nikolay Rusev
    Nikolay Rusev avatar
    2276 posts

    Posted 10 Mar 2014 Link to this post

    Hello Scott,

    The reason for this behavior is because the change event of the DropDownList is not triggered when the value is changed from code /see the important block/. 

    To overcome this you will have to execute the code for `ValidationTypeChange` function right after you change the value of the DropDownList.

    Nikolay Rusev

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

  3. UI for ASP.NET AJAX banner
  4. Scott
    Scott avatar
    5 posts
    Member since:
    Jan 2013

    Posted 14 Mar 2014 in reply to Nikolay Rusev Link to this post

    Thanks for your help. Your suggestion pointed me in the right direction. I was able to resolve my issue by calling the "tigger" method on the change event after setting the value of the DropDownList control as you suggested. The line of code that fixed the issue ended up being:


    Thanks for your time,
    Scott Dulock
Back to Top