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

[Solved] Combobox selected not selected in combobox

1 Answer 117 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerard Eikelboom
Top achievements
Rank 1
Gerard Eikelboom asked on 02 Mar 2011, 09:04 AM
Hi,
I read an article in the Forum that combox UI doesn't care about the selected item and that it woukd be solved in the version 2010.3.1110.
Well we just implemented that version and I have a List wich returns an
List<SelectListItem> list = new List<SelectListItem>();

I have a peace of code in my controller class wich fills this list and also sets the selected for one of the list items:
foreach(var ws in UserWebshops)
                {
                    if (ws.WebShop_ID == UserDefaultWebshop)
                    {
                        list.Add(new SelectListItem {Text= ws.Omschrijving, Value= ws.WebShop_ID.ToString(), Selected=true});
                    }
                    else
                    {
                        list.Add(new SelectListItem { Text = ws.Omschrijving, Value = ws.WebShop_ID.ToString()});
                    }
  
                }

In my view I do an Ajax call to the controller. The data I get returned is the list with one item where 'selected=true'.
so the data returned seems to be ok.
Below how the data is bind to the combobox:
success: function (data) {
                    var comboBox = $("#UserDefaultWebshop").data("tComboBox");
                    comboBox.dataBind(data);

The dropdown is filled  but the selected item is not selected.
It seems I am doing somthing wrong, I hope you can help me with it.

Regards,
Gerard Eikelboom

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 02 Mar 2011, 11:25 AM
Hello Gerard,

 
Currently calling dataBind method does not update selected item. This is a known issue which will be fixed in the next official release of Telerik components for ASP.NET MVC. For now you can use this workaround:

var comboBox = $("#UserDefaultWebshop").data("tComboBox");
 comboBox.dataBind(data);
comboBox.select(comboBox.index);

Regards,
Georgi Krustev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
ComboBox
Asked by
Gerard Eikelboom
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or