I have bound a drop down list to the enum of days 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 week day (from dropdown list) which was in enum DayOfWeek i.e. if I select "Sunday" from dropdown, I should be able to pick the int value of "Sunday" in the enum DaysOfWeek (NOT ddlDayOfWeek.selectedValue OR SelectedIndex)
How can I do that without a switch and if (Which I think can be one way)?