Resetting datasource leaves Id as Text in combobox

3 posts, 1 answers
    TAD RHODES avatar
    31 posts
    Member since:
    Jul 2009

    Posted 06 Feb 2013 Link to this post

    I have some odd behavior happening in a combo box.

    I have a simple combo box setup.

                      .HtmlAttributes(new { style = "width: 300px;" })
    I have a link button that calls this javascript code.

    function getVendorsForClass() {
            var txtValue = $("#txtSearchClassVendor").val();
            $.getJSON('@Url.Action("GetVendorListByClass","RCS", new {classes = "class"}, "http")/' + txtValue, function (data) {
                var combo = $("#vendorsforClass").data("kendoComboBox");
    This is the code in the controller that is creating the json object.

    public JsonResult GetVendorListByClass(string classes)
                var vendors = new List<VendorList>();
                var classId = classes.Split('/')[1];
                int outId;
                if (int.TryParse(classId, out outId))
                    vendors = new VendorListFactory().GetVendors(outId);
                return this.Json(vendors.Select(v => new { v.Name, v.Id }), JsonRequestBehavior.AllowGet);
    Everything works perfectly on the first time I click on the link to populate the combo box.  If I select a value in the combo box, say for example it's Id happens to be 1234, when I click on the link again (with the intention of repopulating the combo box with different set of values) with a different value that returns back an empty object (no results in the list), the combo box is left with no values in the drop down (which would be correct), but the text in the combo box say 1234.

    The box is left with the Id on the previous value I selected.  I thought when I call setDataSource it rebinds the combo box, meaning it removes previously selected values.  Why is the combo box setting it's text as the previous value (Id) that I had selected when the second datasource happens to be an empty list?

  2. Answer
    Alexander Valchev
    Alexander Valchev avatar
    2873 posts

    Posted 08 Feb 2013 Link to this post

    Hi Tad,

    Thank you for contacting us.

    The value that you see is actually the value of the ComboBox' input element which does not reset automatically. The solution would be to reset it manually after rebind. Please try the following:
    combo.value(""); //clear the value

    Refresh method have other purpose - to re-render the items of the widget's drop-down list.

    Kind regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
    TAD RHODES avatar
    31 posts
    Member since:
    Jul 2009

    Posted 08 Feb 2013 Link to this post

    Excellent...thank you.
Back to Top