This is a migrated thread and some comments may be shown as answers.

DropDownListFor - clear items and repopulate with JS

1 Answer 121 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Shahar
Top achievements
Rank 1
Shahar asked on 24 Jul 2013, 01:32 PM
Hi,
I have a DropDownList that is initially binded on the server side with BindTo method (I am using DropDownListFor).
On the client (JS code) I need to clear its items and then repoppulate the control with other items.
What is the best practice to accomplish this?

Thanks,
Lauri

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 26 Jul 2013, 08:35 AM
Hello Shachar,

Basically to control what items are used by the DropDownList you need to use the dataSource objects and its methods.

In your case you will need to get reference to the client object and use the dataSource.data() method. 

e.g.

var ds = $('#ddlName').data().kendoDropDownList.dataSource;
ds.data([{PersonID:1,FirstName:"Shachar"},{PersonID:2,FirstName:"Petur"}])
// make sure that the objects that you use to populate the dataSource have the same fields as the ones that you specified in the DataTextField and DataValueField of your DropDownList

I hope this helps.

Kind Regards,
Petur Subev
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
Shahar
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or