---
title: "How to map dropDownlist to enum in C#?"  
description: "How to map dropDownlist to enum in C#?"  
author: "Anonymous User"  
published: 2014-12-01  
updated: 2014-12-02  
canonical: https://www.mindstick.com/forum/12728/how-to-map-dropdownlist-to-enum-in-c-sharp  
category: "asp.net"  
tags: ["c#", "dropdown"]  
reading_time: 1 minute  

---

# How to map dropDownlist to enum in C#?

I have bound a [drop down](https://www.mindstick.com/forum/263/drop-down-list-problem) list to the [enum](https://www.mindstick.com/forum/159626/how-can-i-cast-a-string-to-an-enum) of [days](https://www.mindstick.com/articles/157271/how-to-get-cloudways-free-trial-for-14-days-free) of week like this:

```
    private void BindDayOfWeek()    {        this.ddlDayOfWeek.DataSource = GetWeekDays();        this.ddlDayOfWeek.DataBind();    }     private List<DayOfWeek> GetWeekDays()    {        return Enum.GetValues(typeof(DayOfWeek)).Cast<DayOfWeek>().ToList();    }
```

Now I want to read the int [value of the selected](https://www.mindstick.com/forum/159392/how-to-fetch-the-value-of-the-selected-options-in-drop-down-in-php) week day (from [dropdown list](https://www.mindstick.com/forum/760/dropdown-list-open-hide-behind-another-dropdown-list-on-ie-7)) which was in enum DayOfWeek i.e. if I [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) "Sunday" from dropdown, I should be able to pick the [int value](https://www.mindstick.com/forum/159627/get-the-int-value-from-the-enum-in-c-sharp) of "Sunday" in the enum DaysOfWeek (NOT ddlDayOfWeek.selectedValue OR SelectedIndex)

How can I do that without a [switch](https://www.mindstick.com/blog/104495/switch-bringing-new-advancements-in-the-education-management-system) and if (Which I think can be one way)?

## Replies

### Reply by Anonymous User

```
private void BindDayOfWeek(){   
this.ddlDayOfWeek.DataSource = GetWeekDays();   
this.ddlDayOfWeek.DataTextField = DayOfWeek;   
this.ddlDayOfWeek.DataValueField = (int)DayOfWeek.ToString();   
this.ddlDayOfWeek.DataBind();}
```

Change your bind code to the above. This way the selected item of the drop down list, as all items, will have a text [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) that will be shown to the user and a value for this value, which you will can get it server side. The property value of the item, will give you the number of the selected day.


---

Original Source: https://www.mindstick.com/forum/12728/how-to-map-dropdownlist-to-enum-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
