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

Create ComboBox with values from Sortedlist object

1 Answer 153 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sven
Top achievements
Rank 1
Sven asked on 25 Apr 2013, 06:28 AM
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

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 29 Apr 2013, 08:05 AM
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!
Tags
ComboBox
Asked by
Sven
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or