add a new item and refresh dropdownlist

6 posts, 0 answers
  1. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 31 Oct 2013 Link to this post

    Hello again,
    How can i add a new item to the datasource of the dropdownlist, and after that do a refresh,so i can see the new added item.

    Thanks and regards,
    Daniel
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 31 Oct 2013 Link to this post

    Hi Daniel,

    To accomplish this please use the dataSource's add method. Once the item is added the DropDownList will automatically refresh.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 04 Nov 2013 Link to this post

    kendo.data.dataSource is the source of a dropdownlist?
    the ideea is that i added something using the serverside,the source has the new value,but the dropdown remains with the same elements.
    and i used ajax on client side to call the fill for a dropdown.
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 04 Nov 2013 Link to this post

    Hello Daniel,

    The data of an Ajax bound DropDownList is stored in its DataSource (instance of kendo.data.DataSource). You should obtain a reference to the DataSource via jQuery:
    $("#dropDownListID").data("kendoDropDownList")
        .dataSource.add({"text": "new Item", "value": 1000});

    Where dropDownListID is the ID of the DropDown element, text and value are respectively the dataTextField and the dataValueField of the widget.

    In case you added a record in the data base and would like to fetch the new data from the server, you need to call the read method of the DataSource. Add method inserts new entry on the client.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 06 Nov 2013 Link to this post

    the scenario is exactly the oposite.
    I added a new item on server-side ,the source now it has its new item,and somehow i need to refresh the dropdownlist on the client,the .refresh or the .datasource.Read() does not do the trick.
    or do you mean that what i still need is to call .Read() from the server? in that case how?

    Regards,
    Daniel
  7. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 06 Nov 2013 Link to this post

    Hi Daniel,

    I mean that you should call dataSource.read() (starting with a small letter) on the client side. The method will trigger the read transport of the DataSource which will issue  Ajax request to the server. When the new data is retrieved the DropDownList widget will refresh automatically.

    In case you still have problems please provide the relevant code so we can check your current configuration.

    Regards,
    Alexander Valchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET MVC is VS 2017 Ready