This question is locked. New answers and comments are not allowed.
Hi,
I have a dropdownlist which I'm populating it with a list of enums, and I am passing in the enum I require to be the selected item, this all seems to be set, and the EnumHelper is returning all the correct values, except it doesn't set the selected item, and just sets to the first item in the drop down list.
Any thoughts?
I have a dropdownlist which I'm populating it with a list of enums, and I am passing in the enum I require to be the selected item, this all seems to be set, and the EnumHelper is returning all the correct values, except it doesn't set the selected item, and just sets to the first item in the drop down list.
Any thoughts?
@(Html.Telerik().DropDownList().Name("MyDropDown") .BindTo(new SelectList(EnumHelper.EnumDropDownList<PropertyBased>((int)PropertyBased.Yes) , "Value", "Text", "Selected")))
public static IEnumerable<SelectListItem> EnumDropDownList<T>(int selectedValue) { var items = new List<SelectListItem>(); foreach (int data in Enum.GetValues(typeof(T))) { items.Add(new SelectListItem { //populate a drop down with values, separating camelcase text with a space. Text = Enum.GetName(typeof(T), data).SpaceCamelCase(), Value = data.ToString(), Selected = (data.Equals(selectedValue)) }); } return items; }