Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ken_wilsonii@hotmail.com - 23 Mar 2008 04:10 GMT
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.
Just Me - 23 Mar 2008 10:15 GMT
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.

>I ran into this problem it ended up being a combination of this that
> needed to be done.
[quoted text clipped - 45 lines]
>
>   Best I could come up with.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.