ComboBox selection not sticking when leaving edited column

2 posts, 0 answers
  1. Robert
    Robert avatar
    18 posts
    Member since:
    Feb 2014

    Posted 07 Dec 2016 Link to this post

    I have a grid that is sourced by a List of Objects within my model (local binding).  I need to have the editor for the Name column (the only column in the grid) to be a ComboxBox where they can choose from a specified list.  I got that part working, however, whenever I leave the combobox, it sets the column to the default value for the name field instead of the chosen item from the combobox.  I can not figure out what I am doing wrong.

    Here is my grid:

        .ToolBar(toolbar => { toolbar.Create().Text("Add Location"); })
        .HtmlAttributes(new { style = "height: 150px;" })
        .Columns(columns =>
            columns.Bound(l => l.Name);
            columns.Command(cmd => cmd.Destroy().Text("<i class='fa fa-trash-o'></i>")).Width(50);
        .Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
        .DataSource(ds =>
            .Model(model => { model.Id(p => p.Id); model.Field(l => l.Name).DefaultValue("Select a Location"); })
                .Create(create => create.Action("AddLocationToProcess", "ProjectConfiguration"))
                .Destroy(destroy => destroy.Action("RemoveLocationFromProcess", "ProjectConfiguration"))
            .Events(events => events.Edit("LocationsGrid_edit"))


    Here is my Editor:

    @model int?
    @(Html.Kendo().ComboBoxFor(model => model)
        .Name("SweepTriggeredLocationCB_" + new Random().Next())
        .Placeholder("Select Location...")
        .DataSource(ds =>
            ds.Read(read => read.Action("GetAddProcessLocations", "ProjectConfiguration").Data("GetAddLocationData"));
        .Value(Model.HasValue ? Model.Value.ToString() : null)
        .Events(events => events.Change("StandardComboBox_change"))


    Here is the portion of my Model showing the UIHint for the Editor:

    [Required(ErrorMessage = "{0} is required.")]
    [NoWhiteSpace(ErrorMessage = "{0} cannot begin or end with a space.")]
    public string Name { get; set; }

  2. Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 09 Dec 2016 Link to this post

    Hi Robert,

    There are few issues with your configuration: 
    • The Name of the ComboBox should match exactly the name of the field;
    • The template should accept string value and not int, because from what I see in the model, the Name property is of string type;
    • The DataValueField of the ComboBox should point to "Name" as well, because you are passing that name only

    Please test the above changes and see if the issue is resolved.

    Konstantin Dikov
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
Back to Top