Create ComboBox with values from Sortedlist object

2 posts, 0 answers
  1. Sven
    Sven avatar
    7 posts
    Member since:
    Sep 2011

    Posted 25 Apr 2013 Link to this post

    Hi,

    I am currently making my first
    experiences with Kendo UI and a ASP.NET MVC 4 project. At the moment I have a
    list stored in a standard .Net System.Collections.Sortedlist object and would
    like to fill a Kendo UI combobox with the values from that list. I also tried
    to first build a Kendo datasource object, that contains the elements from that
    Sortedlist, but I could not get that to work.

    How can I:

    • fill a Kendo UI combobox with elements from a .Net System.Collections.Sortedlist
    object?

    or

    • fill a Kendo UI datasource (which I will later use to create the combobox)
    with elements from a .Net System.Collections.Sortedlist object?

    Regards

    Sven
  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 29 Apr 2013 Link to this post

    Hello Sven,

    The SortedList(or any dictionary)is serialized as object and the ComboBox expects an array. You should project the sorted list to a collection of objects in order to bind it to the ComboBox or set it as data to the dataSource e.g.

    @model SortedList<string,string>
     
    @(Html.Kendo().ComboBox()
      .Name("combo")
      .DataTextField("Text")
      .DataValueField("Value")       
      .BindTo(Model.Select(k => new SelectListItem
            {
                Text = k.Value,
                Value = k.Key
            }))
     )
    Regards,
    Daniel
    the Telerik team
    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
Back to Top