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

Issue with enums and dropdownlist control

1 Answer 104 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Heath
Top achievements
Rank 1
Heath asked on 01 Oct 2015, 07:45 PM

Starting with the Q3 release we've seen the following behavior for enum attributes that are bound to a dropdownlist.

  1.  Attribute in model is of type enum
  2. select values passed to the dropdownlist are of type IEnumerable<SelectListItem> with the value of the attribute set as selected.
  3. The dropDownList is populated using .BindTo so is loaded on page load
  4. When the form opens no value is selected in dropdown.  This happens in all cases where a dropdownlist is bound to an enum

I did some testing and found when I bound the dropdownlist to the integer that the enum represented, the dropdownlist worked as expected.  It seems that the control is no longer binding to enums as it did before (binding the value to the integer the enum represents).  Did something change that was undocumented in the Q3 release that caused this behavior?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 05 Oct 2015, 09:24 AM
Hello,

In general, the widget is designed to select an item based on the value. This mapping is done using DataValueField option. Indeed, before widget was selecting Enum value using its string representation, but this behavior had been working by chance. The correct way to select widget's value is to use int value of the Enum. Check the attached test demo.

The change was introduced in Q2 2015 release when we added support for selecting value honoring datasource item type.

Regards,
Georgi Krustev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
DropDownList
Asked by
Heath
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or