View Single Post
 
Old February 6th, 2008, 12:33 AM
Jerminator Jerminator is offline
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Phantom Databinding on drop down list

I have converted a project from ASP.net 1.1 to 2.0 using Visual Studio 2008. I had not touched this code for two years and am having a ton of problems with it. The conversion was successful according to the wizard and it backed up the project in a "backup" folder.
On the front page I have two drop down lists. One called Projects and the other Branches, each is bound to a table in a database using Datareaders. When the "Projects" drop down is changed part of it's query pulls in a BranchID and is supposed to set the Branches drop down to that value.

However each time I change the Projects drop down I get an error that says that the value of the BranchID is outside the range:

dlstBranches has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Stack Trace
[ArgumentOutOfRangeException: 'dlstBranches' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value]
   System.Web.UI.WebControls.ListControl.set_Selected Value(String value) +1827626
   Urgent.PP_New.dlstProject_SelectedIndexChanged(Obj ect sender, EventArgs e) +1069
   System.Web.UI.WebControls.ListControl.OnSelectedIn dexChanged(EventArgs e) +105
   System.Web.UI.WebControls.DropDownList.RaisePostDa taChangedEvent() +134
   System.Web.UI.WebControls.DropDownList.System.Web. UI.IPostBackDataHandler.RaisePostDataChangedEvent( ) +7
   System.Web.UI.Page.RaiseChangedEvents() +117
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1646

So I checked the databinding code for the Branches drop down and I found that it is being declared somewhere besides the PageLoad event. And thus the values are wrong. I even commented out the binding code in the PageLoad and still the Branches drop down was populated when I ran the page.

Is there something I'm missing? I checked the "designer.vb" file and I didn't see any binding code in there. Where else would it be looking? I am at a loss.

I tried putting a SQLDataSource on the page and binding the Branches drop down to that but it came back with the error that the Datasource and DataSourceID propterties were both being set and that I should only set one.

Thanks for any help you can give.