DropDownListFor - clear items and repopulate with JS

2 posts, 0 answers
  1. Shahar
    Shahar avatar
    12 posts
    Member since:
    Jul 2010

    Posted 24 Jul 2013 Link to this post

    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?

  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 26 Jul 2013 Link to this post

    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. 


    var ds = $('#ddlName').data().kendoDropDownList.dataSource;
    // 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
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top