user6672226 user6672226 - 25 days ago 16
ASP.NET (C#) Question

Set the returned data to Kendo Dropdownlist

I am working in ASP.Net MVC. I have a dropdownlist of Kendo and a form to insert data to database and set the recently inserted data to be selected on kendo dropdown.I am using angular for post method.

var response = $http({
method: "post",
url: loadAllProductsUrl,
data: JSON.stringify(customerdetail),
dataType: "json",
async: false
});

$('#customerModal').modal('hide');
return response.then(function (data) {
if (data != null) {
$("#customers").data("kendoDropDownList").dataSource.read();
setToDropdown(data);

}
else {

}
});


This is my Post method and from here I return the Customer Code and set it to the kendo dropdownlist.

function setToDropdown(data) {

var temp = $("#customers").data("kendoDropDownList");
temp.select(function (dataItem) {
return dataItem.CustomerCode === data;
});
}


But the data is not being set to the dropdownlist because setToDropdown(data) is executed before $("#customers").data("kendoDropDownList").dataSource.read(); is loaded fully. Please suggest....

Answer

this helped me

 getCustomer(function (a) {

                            setTimeout(function () {

                                $("#customers").data("kendoDropDownList").value(data.CustomerName);
                            }, 100);

                        });
Comments