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

  • Question

  • User-1410199723 posted
    Dear all,

    I have a FormView in a page. It contains cascading DropDownLists that work fine in InsertItemTemplate. When I try to edit a record (switching to EditItemTemplate from ItemTemplate), I get error: 'ddlCategories' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value.

    In this EditItemTemplate, I bound the first DDL with ObjectDataSource (ODS). The ODS runs SelectMethod that selects out all records in table "Category".

    I understand from browsing the Internet that this error is caused by the following:

    1. Binding the DDL to a database field that is NULL. I have checked by running the Select Command in the TableAdapter using Preview Data. The command return all records.

    2. The Select Command returns record values that are not part of the DDL items. I have checked that the DDL item from the record I try to edit has one of the values returned by the TableAdapter Select Command.

    Note both checking are done off-line. I do not know how to check by using debugging.

    My question is: How do I solve my problem?

    Regards,
    Garreth Goh
    Wednesday, August 13, 2008 12:06 PM

Answers

  • User-1995538749 posted

    Besides nulls or emptystrings, make sure that the SelectedValue does not have an additonal spaces appended to it. Any difference between your SelectedValue and the items within the DropDownList will cause this error.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 13, 2008 12:32 PM

All replies

  • User-1995538749 posted

    Besides nulls or emptystrings, make sure that the SelectedValue does not have an additonal spaces appended to it. Any difference between your SelectedValue and the items within the DropDownList will cause this error.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 13, 2008 12:32 PM
  • User-1410199723 posted

    You are right. I had my "Category" column length differed between transaction and master tables. The problem is solved after correcting them. Thank you.

    Regards,
    Garreth Goh

    Wednesday, August 13, 2008 12:54 PM