I currently have a DropDownList inside a FormView, binding data to an ObjectDataSource. This is a DropDownList that has its own data source that returns a list of departments:
<asp:DropDownList ID="DepartmentsList" DataSourceID="DepartmentsListDataSource" DataTextField="Name" SelectedValue='<%# Bind("Department") %>' runat="server" />
In a FormView data source, a property department is defined as:
public Department Department { get; set; }
In this situation, I get this exception:
'DepartmentsList' has a SelectedValue value, which is not valid because it does not exist in the list of elements. Parameter Name: Value
Logically, I get this exception because I did not set the DataValueField to DropDownList. The question is what should be the value of a DataValueField if I would like to bind the full selected object (department) to the FormViews data source?
Thanks.
Herman cordes
source share