Replace datasource of a dropdownlist

1 Answer 4730 Views
DropDownList
Sean
Top achievements
Rank 1
Sean asked on 04 Nov 2013, 04:17 PM
I'm interested in the most efficient way to replace a dataSource for a named dropdownlist (ex: $("#DDL1"). The control is referenced throughout the application therefore I just want to change the datasource.

I want to change the dataSource details inline like so:
$("#DDL1").kendoDropDownList({ dataSource: _urlStates, dataTextField: "attributes.States", dataValueField: "attributes.States" }).data("kendoDropDownList");
But I'm overlooking something...

Thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 05 Nov 2013, 08:13 AM
Hello Todd,

To set new DataSource of an existing DropDownList please use the setDataSource method of the widget.
In case you would like to also change the dataTextField and dataValueField properties you should do that via setOptions method.

For example:
$("#dropdownlist").data("kendoDropDownList")
    .setOptions({ dataTextField: "text_new", dataValueField: "value_new" });
 
$("#dropdownlist").data("kendoDropDownList").setDataSource(newds);

I hope this will help.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
DropDownList
Asked by
Sean
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or