Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdownlist problem

Status
Not open for further replies.

rnooraei

Programmer
Apr 5, 2005
74
CA
Hi
Here is my problem. I save a records with different dropdownlist. Let's say if I saved it without a dropdwonlist and the try to load it again. I get the following error message.I understand it try to select a value which is not there so what is the solution at this point. any help appreciated.
Thanks



'ddlAppDevTool' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
 
there's two things i can say here...

if you are using a bound form, i wont be able to help at all, sorry...

if it's an unbound form, then when you're populating the drop down, check to see if there's a value from your datastore in that field first.

such as

Code:
if isnull(your variable or dataholder) = false
   dropdown.items.findbytext(your variable or dataholder).selected = true
end if


Life is change. To deny change is to deny life.
 
Thanks for your answer, but I would like to populate the dropdown again even there is no corresponding record in dropdown
 
You need to post the code you are using. Are you binding the ddl then selecting an item based on a value? More info is needed.
 
I have coded everything in VB
This is part of my code in page_load event (in edit page)

If Not IsDBNull(rdr("AppDevTool")) Then
ddlAppDevTool.Text = rdr("AppDevTool")
ViewState("InsertBlank1") = "n"
End If
then I would like to have a blank line at beginning of dropdown in case if user wants to save it with nothing, but my problem is started when the dropdown load it with not corresponding value. so in my case even doesn't matter if I have PreRender event or not.which means the previous value saved in my original table was empty string

Protected Sub ddlAppDevTool_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAppDevTool.PreRender
If ViewState("InsertBlank1") <> "n" Then
ddlAppDevTool.Items.Insert(0, " ")
ViewState("InsertBlank1") = "n"
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top