I have defined an enum like
public Enum CompanyQuarters
{
First=1,
Second=2,
Third=3,
Fourth=4
}
I bind them to dropdown list like
ddlCompQuarter.DataSource = Enum.GetNames(typeof(CompanyQuarters));
ddlCompQuarter.DataBind();
Now I want to fetch the dropdownlist selected value For e.g for selection 'second' I like to fetch 2 ?
This does not work
int selectedVal = int.Parse(ddlCompQuarter.SelectedValue.ToString());
ActiveQuarters value = (ActiveQuarters)Enum.Parse(typeof(ActiveQuarters),ddlCompQuarter.SelectedValue.ToString());
or if you are using Dot Net Framework 4 or greater, see Enum.TryParse
ActiveQuarters value;
Enum.TryParse<ActiveQuarters>(ddlCompQuarter.SelectedValue.ToString(), out value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With