<p>Let's say I have the following simple enum:</p>

<pre><code>enum Response
{
    Yes = 1,
    No = 2,
    Maybe = 3
}
</code></pre>

<p>How can I bind this enum to a DropDownList control so that the descriptions are displayed in the list as well as retrieve the associated numeric value (1,2,3) once an option has been selected?</p>

[{'answer_id': 61961, 'author': 'Mark Glorie', 'author_id': 952, 'author_profile': 'https://Stackoverflow.com/users/952', 'pm_score': 8, 'selected': True, 'text': "<p>I probably wouldn't <strong>bind</strong> the data as it's an enum, and it won't change after compile time (unless I'm having one of those <em>stoopid</em> moments).  </p>\n\n<p>Better just to iterate through the enum:  </p>\n\n<pre><code>Dim itemValues As Array = System.Enum.GetValues(GetType(Response))\nDim itemNames As Array = System.Enum.GetNames(GetType(Response))\n\nFor i As Integer = 0 To itemNames.Length - 1\n    Dim item As New ListItem(itemNames(i), itemValues(i))\n    dropdownlist.Items.Add(item)\nNext\n</code></pre>\n\n<p>Or the same in C#  </p>\n\n<pre><code>Array itemValues = System.Enum.GetValues(typeof(Response));\nArray itemNames = System.Enum.GetNames(typeof(Response));\n\nfor (int i = 0; i &lt;= itemNames.Length - 1 ; i++) {\n    ListItem item = new ListItem(itemNames[i], itemValues[i]);\n    dropdownlist.Items.Add(item);\n}\n</code></pre>\n"}, {'answer_id': 61962, 'author': 'roman m', 'author_id': 3661, 'author_profile': 'https://Stackoverflow.com/users/3661', 'pm_score': 1, 'selected': False, 'text': '<p>That\'s not quite what you\'re looking for, but might help:</p>\n\n<p><a href="http://blog.jeffhandley.com/archive/2008/01/27/enum-list-dropdown-control.aspx" rel="nofollow noreferrer">http://blog.jeffhandley.com/archive/2008/01/27/enum-list-dropdown-control.aspx</a></p>\n'}, {'answer_id': 61965, 'author': 'rudigrobler', 'author_id': 5147, 'author_profile': 'https://Stackoverflow.com/users/5147', 'pm_score': 3, 'selected': False, 'text': '<p>I am not sure how to do it in ASP.NET but check out <a href="https://stackoverflow.com/questions/58743/databinding-an-enum-property-to-a-combobox-in-wpf#58819">this</a> post... it might help?</p>\n\n<pre><code>Enum.GetValues(typeof(Response));\n</code></pre>\n'}, {'answer_id': 62023, 'author': 'Leyu', 'author_id': 3359, 'author_profile': 'https://Stackoverflow.com/users/3359', 'pm_score': 6, 'selected': False, 'text': '<p>Use the following utility class <code>Enumeration</code> to get an <code>IDictionary&lt;int,string&gt;</code> (Enum value &amp; name pair) from an <strong>Enumeration</strong>; you then bind the <strong>IDictionary</strong> to a bindable Control.</p>\n\n<pre><code>public static class Enumeration\n{\n    public static IDictionary&lt;int, string&gt; GetAll&lt;TEnum&gt;() where TEnum: struct\n    {\n        var enumerationType = typeof (TEnum);\n\n        if (!enumerationType.IsEnum)\n            throw new ArgumentException("Enumeration type is expected.");\n\n        var dictionary = new Dictionary&lt;int, string&gt;();\n\n        foreach (int value in Enum.GetValues(enumerationType))\n        {\n            var name = Enum.GetName(enumerationType, value);\n            dictionary.Add(value, name);\n        }\n\n        return dictionary;\n    }\n}\n</code></pre>\n\n<p><strong>Example:</strong> Using the utility class to bind enumeration data to a control</p>\n\n<pre><code>ddlResponse.DataSource = Enumeration.GetAll&lt;Response&gt;();\nddlResponse.DataTextField = "Value";\nddlResponse.DataValueField = "Key";\nddlResponse.DataBind();\n</code></pre>\n'}, {'answer_id': 62252, 'author': 'Johan Danforth', 'author_id': 6415, 'author_profile': 'https://Stackoverflow.com/users/6415', 'pm_score': 3, 'selected': False, 'text': '<p>As others have already said - don\'t databind to an enum, unless you need to bind to different enums depending on situation. There are several ways to do this, a couple of examples below.</p>\n\n<p><strong>ObjectDataSource</strong></p>\n\n<p>A declarative way of doing it with ObjectDataSource. First, create a BusinessObject class that will return the List to bind the DropDownList to:</p>\n\n<pre><code>public class DropDownData\n{\n    enum Responses { Yes = 1, No = 2, Maybe = 3 }\n\n    public String Text { get; set; }\n    public int Value { get; set; }\n\n    public List&lt;DropDownData&gt; GetList()\n    {\n        var items = new List&lt;DropDownData&gt;();\n        foreach (int value in Enum.GetValues(typeof(Responses)))\n        {\n            items.Add(new DropDownData\n                          {\n                              Text = Enum.GetName(typeof (Responses), value),\n                              Value = value\n                          });\n        }\n        return items;\n    }\n}\n</code></pre>\n\n<p>Then add some HTML markup to the ASPX page to point to this BO class:</p>\n\n<pre><code>&lt;asp:DropDownList ID="DropDownList1" runat="server" \n    DataSourceID="ObjectDataSource1" DataTextField="Text" DataValueField="Value"&gt;\n&lt;/asp:DropDownList&gt;\n&lt;asp:ObjectDataSource ID="ObjectDataSource1" runat="server" \n    SelectMethod="GetList" TypeName="DropDownData"&gt;&lt;/asp:ObjectDataSource&gt;\n</code></pre>\n\n<p>This option requires no code behind.</p>\n\n<p><strong>Code Behind DataBind</strong></p>\n\n<p>To minimize the HTML in the ASPX page and do bind in Code Behind:</p>\n\n<pre><code>enum Responses { Yes = 1, No = 2, Maybe = 3 }\n\nprotected void Page_Load(object sender, EventArgs e)\n{\n    if (!IsPostBack)\n    {\n        foreach (int value in Enum.GetValues(typeof(Responses)))\n        {\n            DropDownList1.Items.Add(new ListItem(Enum.GetName(typeof(Responses), value), value.ToString()));\n        }\n    }\n}\n</code></pre>\n\n<p>Anyway, the trick is to let the Enum type methods of GetValues, GetNames etc. to do work for you.</p>\n'}, {'answer_id': 135822, 'author': 'VanOrman', 'author_id': 4550, 'author_profile': 'https://Stackoverflow.com/users/4550', 'pm_score': 5, 'selected': False, 'text': '<p>My version is just a compressed form of the above:</p>\n\n<pre><code>foreach (Response r in Enum.GetValues(typeof(Response)))\n{\n    ListItem item = new ListItem(Enum.GetName(typeof(Response), r), r.ToString());\n    DropDownList1.Items.Add(item);\n}\n</code></pre>\n'}, {'answer_id': 290408, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': False, 'text': '<pre><code>public enum Color\n{\n    RED,\n    GREEN,\n    BLUE\n}\n</code></pre>\n\n<p>Every Enum type derives from System.Enum. There are two static methods that help bind data to a drop-down list control (and retrieve the value). These are Enum.GetNames and Enum.Parse. Using GetNames, you are able to bind to your drop-down list control as follows:</p>\n\n<pre><code>protected System.Web.UI.WebControls.DropDownList ddColor;\n\nprivate void Page_Load(object sender, System.EventArgs e)\n{\n     if(!IsPostBack)\n     {\n        ddColor.DataSource = Enum.GetNames(typeof(Color));\n        ddColor.DataBind();\n     }\n}\n</code></pre>\n\n<p>Now if you want the Enum value Back on Selection ....</p>\n\n<pre><code>  private void ddColor_SelectedIndexChanged(object sender, System.EventArgs e)\n  {\n    Color selectedColor = (Color)Enum.Parse(typeof(Color),ddColor.SelectedValue\n  }\n</code></pre>\n'}, {'answer_id': 540741, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<pre><code>Array itemValues = Enum.GetValues(typeof(TaskStatus));\nArray itemNames = Enum.GetNames(typeof(TaskStatus));\n\nfor (int i = 0; i &lt;= itemNames.Length; i++)\n{\n    ListItem item = new ListItem(itemNames.GetValue(i).ToString(),\n    itemValues.GetValue(i).ToString());\n    ddlStatus.Items.Add(item);\n}\n</code></pre>\n'}, {'answer_id': 1831886, 'author': 'Mostafa', 'author_id': 1904217, 'author_profile': 'https://Stackoverflow.com/users/1904217', 'pm_score': 1, 'selected': False, 'text': '<p>Why not use like this to be able pass every listControle :\n<pre><code>\npublic static void BindToEnum(Type enumType, ListControl lc)\n        {\n            // get the names from the enumeration\n            string[] names = Enum.GetNames(enumType);\n            // get the values from the enumeration\n            Array values = Enum.GetValues(enumType);\n            // turn it into a hash table\n            Hashtable ht = new Hashtable();\n            for (int i = 0; i &lt; names.Length; i++)\n                // note the cast to integer here is important\n                // otherwise we\'ll just get the enum string back again\n                ht.Add(names[i], (int)values.GetValue(i));\n            // return the dictionary to be bound to\n            lc.DataSource = ht;\n            lc.DataTextField = "Key";\n            lc.DataValueField = "Value";\n            lc.DataBind();\n        }\n</pre></code>\nAnd use is just as simple as :\n<pre><code>\nBindToEnum(typeof(NewsType), DropDownList1);\nBindToEnum(typeof(NewsType), CheckBoxList1);\nBindToEnum(typeof(NewsType), RadoBuuttonList1);\n</pre></code></p>\n'}, {'answer_id': 2080385, 'author': 'Muhammed Qasim', 'author_id': 252516, 'author_profile': 'https://Stackoverflow.com/users/252516', 'pm_score': 2, 'selected': False, 'text': '<p>Generic Code Using Answer six.</p>\n\n<pre><code>public static void BindControlToEnum(DataBoundControl ControlToBind, Type type)\n{\n    //ListControl\n\n    if (type == null)\n        throw new ArgumentNullException("type");\n    else if (ControlToBind==null )\n        throw new ArgumentNullException("ControlToBind");\n    if (!type.IsEnum)\n        throw new ArgumentException("Only enumeration type is expected.");\n\n    Dictionary&lt;int, string&gt; pairs = new Dictionary&lt;int, string&gt;();\n\n    foreach (int i in Enum.GetValues(type))\n    {\n        pairs.Add(i, Enum.GetName(type, i));\n    }\n    ControlToBind.DataSource = pairs;\n    ListControl lstControl = ControlToBind as ListControl;\n    if (lstControl != null)\n    {\n        lstControl.DataTextField = "Value";\n        lstControl.DataValueField = "Key";\n    }\n    ControlToBind.DataBind();\n\n}\n</code></pre>\n'}, {'answer_id': 2416623, 'author': 'Feryt', 'author_id': 82539, 'author_profile': 'https://Stackoverflow.com/users/82539', 'pm_score': 5, 'selected': False, 'text': '<p>I use this for <strong>ASP.NET MVC</strong>:</p>\n\n<pre><code>Html.DropDownListFor(o =&gt; o.EnumProperty, Enum.GetValues(typeof(enumtype)).Cast&lt;enumtype&gt;().Select(x =&gt; new SelectListItem { Text = x.ToString(), Value = ((int)x).ToString() }))\n</code></pre>\n'}, {'answer_id': 2511877, 'author': 'Ben Hughes', 'author_id': 286796, 'author_profile': 'https://Stackoverflow.com/users/286796', 'pm_score': 2, 'selected': False, 'text': "<p>After finding this answer I came up with what I think is a better (at least more elegant) way of doing this, thought I'd come back and share it here.</p>\n\n<p>Page_Load:</p>\n\n<pre><code>DropDownList1.DataSource = Enum.GetValues(typeof(Response));\nDropDownList1.DataBind();\n</code></pre>\n\n<p>LoadValues:</p>\n\n<pre><code>Response rIn = Response.Maybe;\nDropDownList1.Text = rIn.ToString();\n</code></pre>\n\n<p>SaveValues:</p>\n\n<pre><code>Response rOut = (Response) Enum.Parse(typeof(Response), DropDownList1.Text);\n</code></pre>\n"}, {'answer_id': 5120974, 'author': 'Diego Mendes', 'author_id': 484222, 'author_profile': 'https://Stackoverflow.com/users/484222', 'pm_score': 0, 'selected': False, 'text': '<p>This is my solution for Order an Enum and DataBind(Text and Value)to Dropdown using LINQ</p>\n\n<pre><code>var mylist = Enum.GetValues(typeof(MyEnum)).Cast&lt;MyEnum&gt;().ToList&lt;MyEnum&gt;().OrderBy(l =&gt; l.ToString());\nforeach (MyEnum item in mylist)\n    ddlDivisao.Items.Add(new ListItem(item.ToString(), ((int)item).ToString()));\n</code></pre>\n'}, {'answer_id': 5608266, 'author': 'justin', 'author_id': 700363, 'author_profile': 'https://Stackoverflow.com/users/700363', 'pm_score': 0, 'selected': False, 'text': '<p>Both asp.net and winforms tutorial with combobox and dropdownlist:\n<a href="http://www.docstorus.com/viewer.aspx?code=833d27e2-5e3b-4ec0-b950-02c8fc2ec572&amp;title=How%20to%20use%20Enum%20with%20Combobox%20in%20C#%20WinForms%20and%20Asp.Net" rel="nofollow">How to use Enum with Combobox in C# WinForms and Asp.Net</a></p>\n\n<p>hope helps</p>\n'}, {'answer_id': 6517806, 'author': 'sankalp gurha', 'author_id': 820671, 'author_profile': 'https://Stackoverflow.com/users/820671', 'pm_score': 2, 'selected': False, 'text': '<pre><code>public enum Color\n{\n    RED,\n    GREEN,\n    BLUE\n}\n\nddColor.DataSource = Enum.GetNames(typeof(Color));\nddColor.DataBind();\n</code></pre>\n'}, {'answer_id': 7071406, 'author': 'Stuart Leeks', 'author_id': 202415, 'author_profile': 'https://Stackoverflow.com/users/202415', 'pm_score': 0, 'selected': False, 'text': '<p>Check out my post on creating a custom helper "ASP.NET MVC - Creating a DropDownList helper for enums":  <a href="http://blogs.msdn.com/b/stuartleeks/archive/2010/05/21/asp-net-mvc-creating-a-dropdownlist-helper-for-enums.aspx" rel="nofollow">http://blogs.msdn.com/b/stuartleeks/archive/2010/05/21/asp-net-mvc-creating-a-dropdownlist-helper-for-enums.aspx</a></p>\n'}, {'answer_id': 7750678, 'author': 'Josh Stribling', 'author_id': 464386, 'author_profile': 'https://Stackoverflow.com/users/464386', 'pm_score': 0, 'selected': False, 'text': '<p>If you would like to have a more user friendly description in your combo box (or other control) you can use the Description attribute with the following function:</p>\n\n<pre><code>    public static object GetEnumDescriptions(Type enumType)\n    {\n        var list = new List&lt;KeyValuePair&lt;Enum, string&gt;&gt;();\n        foreach (Enum value in Enum.GetValues(enumType))\n        {\n            string description = value.ToString();\n            FieldInfo fieldInfo = value.GetType().GetField(description);\n            var attribute = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).First();\n            if (attribute != null)\n            {\n                description = (attribute as DescriptionAttribute).Description;\n            }\n            list.Add(new KeyValuePair&lt;Enum, string&gt;(value, description));\n        }\n        return list;\n    }\n</code></pre>\n\n<p>Here is an example of an enum with Description attributes applied:</p>\n\n<pre><code>    enum SampleEnum\n    {\n        NormalNoSpaces,\n        [Description("Description With Spaces")]\n        DescriptionWithSpaces,\n        [Description("50%")]\n        Percent_50,\n    }\n</code></pre>\n\n<p>Then Bind to control like so...</p>\n\n<pre><code>        m_Combo_Sample.DataSource = GetEnumDescriptions(typeof(SampleEnum));\n        m_Combo_Sample.DisplayMember = "Value";\n        m_Combo_Sample.ValueMember = "Key";\n</code></pre>\n\n<p>This way you can put whatever text you want in the drop down without it having to look like a variable name</p>\n'}, {'answer_id': 9900016, 'author': 'Trisped', 'author_id': 641833, 'author_profile': 'https://Stackoverflow.com/users/641833', 'pm_score': 0, 'selected': False, 'text': '<p>You could also use Extension methods.  For those not familar with extensions I suggest checking the <a href="http://msdn.microsoft.com/en-us/library/bb384936.aspx" rel="nofollow">VB</a> and <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" rel="nofollow">C#</a> documentation.</p>\n\n<hr>\n\n<p>VB Extension:</p>\n\n<pre><code>Namespace CustomExtensions\n    Public Module ListItemCollectionExtension\n\n        &lt;Runtime.CompilerServices.Extension()&gt; _\n        Public Sub AddEnum(Of TEnum As Structure)(items As System.Web.UI.WebControls.ListItemCollection)\n            Dim enumerationType As System.Type = GetType(TEnum)\n            Dim enumUnderType As System.Type = System.Enum.GetUnderlyingType(enumType)\n\n            If Not enumerationType.IsEnum Then Throw New ArgumentException("Enumeration type is expected.")\n\n            Dim enumTypeNames() As String = System.Enum.GetNames(enumerationType)\n            Dim enumTypeValues() As TEnum = System.Enum.GetValues(enumerationType)\n\n            For i = 0 To enumTypeNames.Length - 1\n                items.Add(New System.Web.UI.WebControls.ListItem(saveResponseTypeNames(i), TryCast(enumTypeValues(i), System.Enum).ToString("d")))\n            Next\n        End Sub\n    End Module\nEnd Namespace\n</code></pre>\n\n<p>To use the extension:</p>\n\n<pre><code>Imports &lt;projectName&gt;.CustomExtensions.ListItemCollectionExtension\n\n...\n\nyourDropDownList.Items.AddEnum(Of EnumType)()\n</code></pre>\n\n<hr>\n\n<p>C# Extension:</p>\n\n<pre><code>namespace CustomExtensions\n{\n    public static class ListItemCollectionExtension\n    {\n        public static void AddEnum&lt;TEnum&gt;(this System.Web.UI.WebControls.ListItemCollection items) where TEnum : struct\n        {\n            System.Type enumType = typeof(TEnum);\n            System.Type enumUnderType = System.Enum.GetUnderlyingType(enumType);\n\n            if (!enumType.IsEnum) throw new Exception("Enumeration type is expected.");\n\n            string[] enumTypeNames = System.Enum.GetNames(enumType);\n            TEnum[] enumTypeValues = (TEnum[])System.Enum.GetValues(enumType);\n\n            for (int i = 0; i &lt; enumTypeValues.Length; i++)\n            {\n                items.add(new System.Web.UI.WebControls.ListItem(enumTypeNames[i], (enumTypeValues[i] as System.Enum).ToString("d")));\n            }\n        }\n    }\n}\n</code></pre>\n\n<p>To use the extension:</p>\n\n<pre><code>using CustomExtensions.ListItemCollectionExtension;\n\n...\n\nyourDropDownList.Items.AddEnum&lt;EnumType&gt;()\n</code></pre>\n\n<hr>\n\n<p>If you want to set the selected item at the same time replace</p>\n\n<pre><code>items.Add(New System.Web.UI.WebControls.ListItem(saveResponseTypeNames(i), saveResponseTypeValues(i).ToString("d")))\n</code></pre>\n\n<p>with</p>\n\n<pre><code>Dim newListItem As System.Web.UI.WebControls.ListItem\nnewListItem = New System.Web.UI.WebControls.ListItem(enumTypeNames(i), Convert.ChangeType(enumTypeValues(i), enumUnderType).ToString())\nnewListItem.Selected = If(EqualityComparer(Of TEnum).Default.Equals(selected, saveResponseTypeValues(i)), True, False)\nitems.Add(newListItem)\n</code></pre>\n\n<p>By converting to System.Enum rather then int size and output issues are avoided.  For example 0xFFFF0000 would be 4294901760 as an uint but would be -65536 as an int.</p>\n\n<p>TryCast and as System.Enum are slightly faster than Convert.ChangeType(enumTypeValues[i], enumUnderType).ToString() (12:13 in my speed tests).</p>\n'}, {'answer_id': 24769726, 'author': 'Amir Chatrbahr', 'author_id': 922713, 'author_profile': 'https://Stackoverflow.com/users/922713', 'pm_score': 4, 'selected': False, 'text': '<p>After reading all posts I came up with a comprehensive solution to support showing enum description in dropdown list as well as selecting proper value from Model in dropdown when displaying in Edit mode:</p>\n\n<p>enum:</p>\n\n<pre><code>using System.ComponentModel;\npublic enum CompanyType\n{\n    [Description("")]\n    Null = 1,\n\n    [Description("Supplier")]\n    Supplier = 2,\n\n    [Description("Customer")]\n    Customer = 3\n}\n</code></pre>\n\n<p>enum extension class:</p>\n\n<pre><code>using System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Linq;\nusing System.Web.Mvc;\n\npublic static class EnumExtension\n{\n    public static string ToDescription(this System.Enum value)\n    {\n        var attributes = (DescriptionAttribute[])value.GetType().GetField(value.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);\n        return attributes.Length &gt; 0 ? attributes[0].Description : value.ToString();\n    }\n\n    public static IEnumerable&lt;SelectListItem&gt; ToSelectList&lt;T&gt;(this System.Enum enumValue)\n    {\n        return\n            System.Enum.GetValues(enumValue.GetType()).Cast&lt;T&gt;()\n                  .Select(\n                      x =&gt;\n                      new SelectListItem\n                          {\n                              Text = ((System.Enum)(object) x).ToDescription(),\n                              Value = x.ToString(),\n                              Selected = (enumValue.Equals(x))\n                          });\n    }\n}\n</code></pre>\n\n<p>Model class:</p>\n\n<pre><code>public class Company\n{\n    public string CompanyName { get; set; }\n    public CompanyType Type { get; set; }\n}\n</code></pre>\n\n<p>and View:</p>\n\n<pre><code>@Html.DropDownListFor(m =&gt; m.Type,\n@Model.Type.ToSelectList&lt;CompanyType&gt;())\n</code></pre>\n\n<p>and if you are using that dropdown without binding to Model, you can use this instead:</p>\n\n<pre><code>@Html.DropDownList("type",                  \nEnum.GetValues(typeof(CompanyType)).Cast&lt;CompanyType&gt;()\n.Select(x =&gt; new SelectListItem {Text = x.ToDescription(), Value = x.ToString()}))\n</code></pre>\n\n<p>So by doing so you can expect your dropdown displays Description instead of enum values. Also when it comes to Edit, your model will be updated by dropdown selected value after posting page.</p>\n'}, {'answer_id': 27000004, 'author': 'bradlis7', 'author_id': 179311, 'author_profile': 'https://Stackoverflow.com/users/179311', 'pm_score': 1, 'selected': False, 'text': '<p>ASP.NET has since been updated with some more functionality, and you can now use built-in enum to dropdown.</p>\n\n<p>If you want to bind on the Enum itself, use this:</p>\n\n<pre><code>@Html.DropDownList("response", EnumHelper.GetSelectList(typeof(Response)))\n</code></pre>\n\n<p>If you\'re binding on an instance of Response, use this:</p>\n\n<pre><code>// Assuming Model.Response is an instance of Response\n@Html.EnumDropDownListFor(m =&gt; m.Response)\n</code></pre>\n'}, {'answer_id': 33767663, 'author': 'KrishnaDhungana', 'author_id': 2330518, 'author_profile': 'https://Stackoverflow.com/users/2330518', 'pm_score': 3, 'selected': False, 'text': '<p>You could use linq:</p>\n\n<pre><code>var responseTypes= Enum.GetNames(typeof(Response)).Select(x =&gt; new { text = x, value = (int)Enum.Parse(typeof(Response), x) });\n    DropDownList.DataSource = responseTypes;\n    DropDownList.DataTextField = "text";\n    DropDownList.DataValueField = "value";\n    DropDownList.DataBind();\n</code></pre>\n'}, {'answer_id': 41553362, 'author': 'Pecheneg', 'author_id': 1872210, 'author_profile': 'https://Stackoverflow.com/users/1872210', 'pm_score': 0, 'selected': False, 'text': "<p>The accepted solution doesn't work, but the code below will help others looking for the shortest solution.</p>\n\n<pre><code> foreach (string value in Enum.GetNames(typeof(Response)))\n                    ddlResponse.Items.Add(new ListItem()\n                    {\n                        Text = value,\n                        Value = ((int)Enum.Parse(typeof(Response), value)).ToString()\n                    });\n</code></pre>\n"}, {'answer_id': 42448307, 'author': 'Marie McDonley', 'author_id': 7307726, 'author_profile': 'https://Stackoverflow.com/users/7307726', 'pm_score': 2, 'selected': False, 'text': '<p>This is probably an old question.. but this is how I did mine.</p>\n\n<p>Model: </p>\n\n<pre><code>public class YourEntity\n{\n   public int ID { get; set; }\n   public string Name{ get; set; }\n   public string Description { get; set; }\n   public OptionType Types { get; set; }\n}\n\npublic enum OptionType\n{\n    Unknown,\n    Option1, \n    Option2,\n    Option3\n}\n</code></pre>\n\n<p>Then in the View: here\'s how to use populate the dropdown.</p>\n\n<pre><code>@Html.EnumDropDownListFor(model =&gt; model.Types, htmlAttributes: new { @class = "form-control" })\n</code></pre>\n\n<p>This should populate everything in your enum list. Hope this helps.. </p>\n'}, {'answer_id': 59394848, 'author': 'Henkie85', 'author_id': 11846363, 'author_profile': 'https://Stackoverflow.com/users/11846363', 'pm_score': 0, 'selected': False, 'text': '<p>You can do this a lot shorter</p>\n\n<pre><code>public enum Test\n    {\n        Test1 = 1,\n        Test2 = 2,\n        Test3 = 3\n    }\n    class Program\n    {\n        static void Main(string[] args)\n        {\n\n            var items = Enum.GetValues(typeof(Test));\n\n            foreach (var item in items)\n            {\n                //Gives you the names\n                Console.WriteLine(item);\n            }\n\n\n            foreach(var item in (Test[])items)\n            {\n                // Gives you the numbers\n                Console.WriteLine((int)item);\n            }\n        }\n    }\n</code></pre>\n'}, {'answer_id': 64668876, 'author': 'MaxOvrdrv', 'author_id': 1583649, 'author_profile': 'https://Stackoverflow.com/users/1583649', 'pm_score': 0, 'selected': False, 'text': '<p>For those of us that want a working C# solution that works with any drop and enum...</p>\n<pre><code>private void LoadConsciousnessDrop()\n{\n    string sel_val = this.drp_Consciousness.SelectedValue;\n    this.drp_Consciousness.Items.Clear();\n    string[] names = Enum.GetNames(typeof(Consciousness));\n    \n    for (int i = 0; i &lt; names.Length; i++)\n        this.drp_Consciousness.Items.Add(new ListItem(names[i], ((int)((Consciousness)Enum.Parse(typeof(Consciousness), names[i]))).ToString()));\n\n    this.drp_Consciousness.SelectedValue = String.IsNullOrWhiteSpace(sel_val) ? null : sel_val;\n}\n</code></pre>\n'}, {'answer_id': 66405336, 'author': 'TheRealSheldon', 'author_id': 3037489, 'author_profile': 'https://Stackoverflow.com/users/3037489', 'pm_score': 0, 'selected': False, 'text': '<p>I realize this post is older and for Asp.net, but I wanted to provide a solution I used recently for a c# Windows Forms Project. The idea is to build a dictionary where the keys are the names of the Enumerated elements and the values are the Enumerated values. You then bind the dictionary to the combobox. See a generic function that takes a ComboBox and Enum Type as arguments.</p>\n<pre><code>    private void BuildComboBoxFromEnum(ComboBox box, Type enumType) {\n        var dict = new Dictionary&lt;string, int&gt;();\n        foreach (var foo in Enum.GetValues(enumType)) {\n            dict.Add(foo.ToString(), (int)foo);\n        }\n        box.DropDownStyle = ComboBoxStyle.DropDownList; // Forces comboBox to ReadOnly\n        box.DataSource = new BindingSource(dict, null);\n        box.DisplayMember = &quot;Key&quot;;\n        box.ValueMember = &quot;Value&quot;;\n        // Register a callback that prints the Name and Value of the \n        // selected enum. This should be removed after initial testing.\n        box.SelectedIndexChanged += (o, e) =&gt; {\n            Console.WriteLine(&quot;{0} {1}&quot;, box.Text, box.SelectedValue);\n        };\n    }\n</code></pre>\n<p>This function can be used as follows:</p>\n<pre><code>BuildComboBoxFromEnum(comboBox1,typeof(Response));\n</code></pre>\n'}, {'answer_id': 68136328, 'author': 'combatc2', 'author_id': 1491388, 'author_profile': 'https://Stackoverflow.com/users/1491388', 'pm_score': 0, 'selected': False, 'text': '<p>In ASP.NET Core you can use the following Html helper (comes from Microsoft.AspNetCore.Mvc.Rendering):</p>\n<pre><code>&lt;select asp-items=&quot;Html.GetEnumSelectList&lt;GridReportingStatusFilters&gt;()&quot;&gt;\n     &lt;option value=&quot;&quot;&gt;&lt;/option&gt;\n&lt;/select&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/61953', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4872/']