I have the following drop down in my aspx:
<aspx:DropDownList
ID="ddl1"
runat="server"/>
In the code-behind (C#), I want to retrieve the value from the DropDownList.
I populated my dropdown as such:
ddl1.DataSource = LocationOfData;
ddl1.DataBind();
LocationOfData returns of type CustomType. EDIT: CustomType is an enum.
I want to be able to accomplish the following:
CustomType? myvar = ddl1.Text
In other words, create a nullable variable using my CustomType and set it equal to the variable from the drop down. But the type that I can only retrieve Text (String) from ddl1.
If
CustomTypeis an Enum you first have to parse yourddl1.Textto an Enum and then cast it to a Nullable type: