Re: Solution to: dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



OK, here's another view on this.... ( Untested )

Instead of having "--Select Username" as a Value AND as Text. Make the
value "" for the Value that way an empty field should select option 0 (
Select UserName ). This would solve the saving null values as well.



<ken_wilsonii@xxxxxxxxxxx> wrote in message
news:17382a93-02f1-45ab-970e-b3c5d62ccba9@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I ran into this problem it ended up being a combination of this that
needed to be done.
I believe this will work for a bound list to.

The whole problem stems from the two-way binding which has caused me
several other headaches.

My example is derived from binding a DETAILSVIEW to a SQLDATASOURCE.
The field is then converted to a template field for which I modify the
EditTemplate for that
field to dropdownlist and then bind it to another sqldatasource for
the dropdown list values.

The error occurs because I am trying to edit the data and the
datafield is empty.
The NULL value causes the error because the value is not in the
dropdown list.

Solution

1) modify the AppendDataBoundItems property of the dropdownlist and
set it to true
and make sure it's bound to field you need to update.

2) add an and Item to the Collection and use something similar to "--
Select Username --"
depends on what the user will be selecting. Make sure the select
is set to true.

3) Modify the Select query for the sqldatasource that the detailsview
is bound to
to account for the null value have it match what was added to
collection in step 2

ISNULL(Username,'-- Select Username --') as Username

4) Step 3 takes care of the error but now you must account for the Two-
Way Binding
and insure that '-- Select Username --' is not the value saved
back to the database if nothing
else is slected from the list.

Modify the Update query back to the data for the same datasource
so a null value
is applied just in case '-- Select Username --' is still selected.

Username = NULLIF(@Username,'-- Select Username --')

Best I could come up with.


.



Relevant Pages

  • Solution to: dropdownlist has a SelectedValue which is invalid because it does not exist in the list
    ... My example is derived from binding a DETAILSVIEW to a SQLDATASOURCE. ... The field is then converted to a template field for which I modify the ... Step 3 takes care of the error but now you must account for the Two- ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Modify SqlDataSource parameters before select
    ... But how to continue from there, how do I access and modify the ... > SqlDataSource control's "Selecting" event, this event get fired before the ... > actual execute command being executed. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: understanding function parameters
    ... fact a pointer to a daisy chain of standard pairs, ... structure and never modify any already-existing structure. ... The second function didn't modify the binding of its local copy of your ...
    (comp.lang.lisp)
  • RE: Modify SqlDataSource parameters before select
    ... As for the modifying SqlDataSource's parameters before the select command ... SqlDataSource control's "Selecting" event, this event get fired before the ... actual execute command being executed. ... Modify SqlDataSource parameters before select ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Avoiding COMs inability to handle overloaded methods
    ... How can I modify a type library? ... Juan Dent, M.Sc. ... But if your COM clients use early binding you can modify the type ... > Please reply only to the newsgroup. ...
    (microsoft.public.dotnet.framework.interop)