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

Enum in Grid's dropdown list column (edit popup mode)

2 Answers 912 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nirav
Top achievements
Rank 1
Nirav asked on 22 Apr 2013, 01:06 PM
Hi,

I want to display an enum in my dropdown list column of Kendo Grid.
I get an success till binding the enum in a dropdown list and displaying it to the Grid. But however it displays as a textbox instead of a dropdown list when I add/edit an item in edit popup. It shows proper dropdown list in InLine editing mode.
One more issue is it displays enum values (1, 2 or 3) instead of enum texts (Red, Amber or Green) in a grid.

My grid column is:
columns.Bound(r => r.RagStatus).EditorTemplateName("RAGStatus");
 
Enum is:
public enum RAGStatus
{
           Red = 1,
            Amber = 2,
            Green = 3,
}
 
public static List<SelectListItem> EnumToSelectList(Type enumType)
{
            return Enum
              .GetValues(enumType)
              .Cast<int>()
              .Select(i => new SelectListItem
                {
                    Value = i.ToString(),
                    Text = Enum.GetName(enumType, i),
                }
              )
              .ToList();
}
 
Enum template is:
@model int
@(
 Html.Kendo().DropDownListFor(m => m)
        .BindTo(EnumToSelectList(typeof(RAGStatus)).ToList())
        .OptionLabel(optionLabel: "Please Select")
        .SelectedIndex(0)
)
Please help.

Thanks,
Nirav


2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 24 Apr 2013, 11:31 AM
Hello,

In popup editing the Grid uses the EditorForModel helper so you should specify the editor with the UIHint attribute.
I am not sure what is causing the problem with displaying the text. I attached a small sample project that uses popup editing. Let me know if I am missing something.

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!
0
Shawn
Top achievements
Rank 2
answered on 11 Feb 2014, 07:22 PM
Thanks this ended a LOT of frustration for me!
Tags
Grid
Asked by
Nirav
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Shawn
Top achievements
Rank 2
Share this question
or