I've looked around this and SO, and was able to find a way (as far as I can tell) to bind the drop-down to the enum, however, I can't seem to get it to bind before then taking a value from the FormView's data source. Relevant code posted below, as well as the error I am getting. Is anything jumping out at all to anyone?
The control I'm Trying to Bind An enum to, and then get current value from datasource of the FormView it resides within:
<ItemTemplate><div class="form-group"><label class="col-md-4 control-label" for="">Listing Status </label><div class="col-md-8"><asp:DropDownList ID="ListingStatus" runat="server" CssClass="form-control" SelectedValue='<%# Bind("ListingStatus")%>'></asp:DropDownList></div></div></ItemTemplate>
Code-Behind Where the enum Binds To the DropDown List:
protected void FormView_DataBound(object sender, EventArgs e) { DropDownList ListingStatus = (DropDownList)FormView.FindControl("ListingStatus"); ListingStatus.DataSource = Enum.GetNames(typeof(ListingStatus)); ListingStatus.DataBind(); }
Error I Am Getting (Same Error If I Put Above Code In the Formview_DataBinding Method):
'ListingStatus' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value System.ArgumentOutOfRangeException: 'ListingStatus' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
Thanks much!