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

  • Question

  • User-1050146888 posted

    I am facing a prob in ASP.NET 2.0 with VB.NET 2005.

    I am using a DDL with values from a lookup table.

    In read-only or edit mode of a FORMVIEW, when the record doesn't exist in the table (maybe because user deletes) ,the DropDownList SelectedValue property of the value from the field is not located in the DropDownList. & so i get the foll error:

    'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items

    Is there any way to stop the DDL from binding if there is no matching records found in the lookup table & perform a databing if any record exists in the lookup table ?





    Friday, June 8, 2007 7:44 PM

All replies

  • User1754323106 posted

     Normally, I always do a check

           //select your value in the drop downlist

    Friday, June 8, 2007 9:23 PM
  • User-1050146888 posted

    Thanks for replying. Could you explain with the entire code. In which event  do i have to put the code ?



    Saturday, June 9, 2007 1:57 AM
  • User-512755392 posted

    Hi Alex,

    Please do something like this:

    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="ID" DataTextField="Text"
    DataValueField="ID" SelectedValue='<%# Eval("ID") != null ? Bind("ID") : "" %>' AppendDataBoundItems=true>

    <asp:ListItem Text="" Value=""></asp:ListItem>


    This will bind the item to "" if the ID is null.

    Please feel free to let us know if you need more assistance.Thanks.

    Tuesday, June 12, 2007 3:50 AM
  • User-1050146888 posted

    Hi Young, 

    Appreciate ur reply. Cannot seem to get ur code working .....Getting Identifier expected, Null is no longer supported errors.....

    My DDL code is as follows: 

    <cc1:KeySortDropDownList ID="KeySortDropDownList6" runat="server" CaseSensitiveKeySort="False"
                        DataSourceID="SqlDataSource6" DataTextField="CriteriaSubName" DataValueField="CriteriaParaID"
                        Enabled="False" Font-Bold="True" Font-Underline="False" SelectedValue='<%# xx(DataBinder.Eval(Container.DataItem,"Para1")) %>'
                        Style="color: blue" Width="500px">

    I need to check if the PARA1 value exists. If it exists in the lookup it should return otherwise it shud display ""

    Pls. help


    Monday, July 2, 2007 4:13 PM