locked
SelectedValue which is invalid because it does not exist in the list of items. RRS feed

  • Question

  • User-378033318 posted

    Hi:

     

    I get "SelectedValue which is invalid because it does not exist in the list of items" because my ddlCampus and other ddls on the detailsview form have a null value in the table.

    I have 2 detailsview forms.  With the form 1 a record is created and inserted into table.   Wth the second detailsview form2 other fields in the record in the same table are updated.  Form1 is inserted creates null values in eg. campus field (int).  In form 2 I use the dropdown to select Campus.  Dropdown takes the value from the lookup table (CampusId -  value, int, and CampusName, text- char) in the SQL query.  Many other fields are updated with the form 2 with the object source update method.

    If I enter manually the vaules to table and try to update records with the Form2 I do not get an error. I would greatly appreciate your assistance as I do not have much

     

     

    Monday, March 17, 2008 9:22 AM

Answers

  • User-1995538749 posted

    You need to make sure that your DropDownList includes any value which possibly may come through the field that you are binding to the SelectedValue property. Therefore, if your field can contain a NULL value, you must make sure that you add a blank ListItem to your DropDownList.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 17, 2008 10:07 AM

All replies

  • User-1995538749 posted

    You need to make sure that your DropDownList includes any value which possibly may come through the field that you are binding to the SelectedValue property. Therefore, if your field can contain a NULL value, you must make sure that you add a blank ListItem to your DropDownList.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 17, 2008 10:07 AM
  • User-378033318 posted

    Hello:

    Thanks for your explanation - I finally understand what my problem was.  I did it with asp code as advised earlier, like this:

     AppendDataBoundItems="True"

    DataSourceID="SqlDataSource4" DataTextField="CampusName" DataValueField="CampusId"

    SelectedValue='<%# Bind("Campus") %>'>

    <asp:ListItem Selected="True" Value="">---- empty value----</asp:ListItem>

     

    Monday, March 17, 2008 11:43 AM