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 / June 2007

Tip: Looking for answers? Try searching our database.

Avoiding "SelectedValue which is invalid because it does not exist in the list of items"

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 30 Jun 2007 00:25 GMT
Why doesn't this work?

My webpage changes databound items in a dropdown list depending on
what form the user selects.  And the page needs to remember what the
user selected, and reselect the dropdown items between posts (using
selectedValue).

The problem is I get the above "does not exist" error when the user
switches forms because of the list changing.

So, I was trying to make a function search for the text in the list
and return a default value (or null) if necessary.

Here is the list:

<asp:dropdownlist SelectedValue='<%# rFolding() %>' ID="tFolding"
runat="Server" cssclass="formfield" datasourceid="ListFoldingSource"
DataTextField="Item" DataValueField="Item"/></td>

And the relevant function looks something like this:

 String rFolding()
 {
     String rtn = ...read from database...
     // Look for the string in the list
     ListItem lstitem = tFolding.Items.FindByText(rtn);
     if (lstitem == null) rtn = "(Select)";  // if not found,
"(Select)" is in every dropdown list so use it
     return rtn;
 }

This halfway works, but I'm still getting the error when the user
switches forms and the list items change.  I expected this technique
to avoid ever getting: "SelectedValue which is invalid because it does
not exist in the list of items."  Did I make some silly mistake or is
there an overall problem?  Why doesn't this work?
nahid - 30 Jun 2007 05:35 GMT
> Why doesn't this work?
>
[quoted text clipped - 32 lines]
> not exist in the list of items."  Did I make some silly mistake or is
> there an overall problem?  Why doesn't this work?

hi,
please check you are binding the list after checking ispostback

if(!ispostback)
{
//bind the combo here
}

hope this help

nahid
http://nahidulkibria.blogspot.com/
http://kaz.com.bd/
Dave - 30 Jun 2007 18:15 GMT
> > Why doesn't this work?
>
[quoted text clipped - 46 lines]
>
> - Show quoted text -

Thanks!  I was doing it all wrong.  That way appears to work
beautifully in my situation.

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.