Setting default value of a dropDownList

user2012783 picture user2012783 · Oct 15, 2013 · Viewed 11.4k times · Source

ive been using this to set a default text form input on a kendo grid which works fine.

 e.container.find("input[name=policy]").val(lender_policy).change();

however if i try and set a default value of a dropDownListlike below, it sets the value of the dropdownlist, but it insert blank data to the grid and DB. im guessing its because change() may need to be called like the text input but am not sure how that can be done.

 e.container.find("input[name=lender]").data("kendoDropDownList").value(lender);

any help on this would be great.

Answer

Vojtiik picture Vojtiik · Oct 15, 2013

1) For dropdown list use select

var dropdownlist = $("#dropdownlist").data("kendoDropDownList");
dropdownlist.select(1);

(There are different options how to select specific item.)

Grid edit event example with your drop down list,

 edit: function(e) {
    if (e.model.isNew()) {
        var ddl = e.container.find("input[name=id]").data("kendoDropDownList");
        ddl.select(1);
    }
  } 

2) This is how to use custom editor in your grid, just in case your dropdown is not populated yet.

3) You could also use OptionLabel