'DropDownList' has a SelectedValue which is invalid

wings9697

Member
Joined
Aug 27, 2007
Messages
23
Location
Washington, DC
Programming Experience
10+
Hi. New Question...

I was binding a DropDownList back to its SQL table field on my CaseEdit Template by going through the wizard, and thought I was OK. But when I ran the page I got this :

'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[ArgumentOutOfRangeException: 'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value]
System.Web.UI.WebControls.ListControl.PerformDataBinding(IEnumerable dataSource) +964
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +80
System.Web.UI.WebControls.ListControl.PerformSelect() +32
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.Control.DataBind() +31
System.Web.UI.Control.DataBindChildren() +236
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +178
System.Web.UI.WebControls.FormView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3050
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +90
System.Web.UI.WebControls.FormView.PerformDataBinding(IEnumerable data) +30
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +126
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +98
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.FormView.DataBind() +23
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +91
System.Web.UI.WebControls.FormView.EnsureDataBound() +176
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +101
System.Web.UI.Control.EnsureChildControls() +134
System.Web.UI.Control.PreRenderRecursiveInternal() +109
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Control.PreRenderRecursiveInternal() +233
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4437

which confused the cr#p out of me, because I have another dropdownlist which is binded back to the SQL table field and works fine. I looked at the XML code and can't see anything that would cause this error.

VB.NET:
 <td style="width: 100px">
                        <asp:DropDownList ID="DropDownList2" runat="server" Width="115px" SelectedValue='<%# Bind("case_psa") %>'>
                            <asp:ListItem Value="000">000</asp:ListItem>
                            <asp:ListItem Value="101">101</asp:ListItem>
                            <asp:ListItem Value="102">102</asp:ListItem>
                            <asp:ListItem Value="103">103</asp:ListItem>
                            <asp:ListItem Value="104">104</asp:ListItem>
                            <asp:ListItem Value="105">105</asp:ListItem>
                            <asp:ListItem Value="106">106</asp:ListItem>
                            <asp:ListItem Value="107">107</asp:ListItem>
                            <asp:ListItem Value="201">201</asp:ListItem>
                            <asp:ListItem Value="202">202</asp:ListItem>
                            <asp:ListItem Value="203">203</asp:ListItem>
                            <asp:ListItem Value="204">204</asp:ListItem>
                            <asp:ListItem Value="205">205</asp:ListItem>
                            <asp:ListItem Value="206">206</asp:ListItem>
                            <asp:ListItem Value="207">207</asp:ListItem>
                            <asp:ListItem Value="208">208</asp:ListItem>
                            <asp:ListItem Value="301">301</asp:ListItem>
                            <asp:ListItem Value="302">302</asp:ListItem>
                            <asp:ListItem Value="303">303</asp:ListItem>
                            <asp:ListItem Value="304">304</asp:ListItem>
                            <asp:ListItem Value="305">305</asp:ListItem>
                            <asp:ListItem Value="306">306</asp:ListItem>
                            <asp:ListItem Value="307">307</asp:ListItem>
                            <asp:ListItem Value="308">308</asp:ListItem>
                            <asp:ListItem Value="401">401</asp:ListItem>
                            <asp:ListItem Value="402">402</asp:ListItem>
                            <asp:ListItem Value="403">403</asp:ListItem>
                            <asp:ListItem Value="404">404</asp:ListItem>
                            <asp:ListItem Value="405">405</asp:ListItem>
                            <asp:ListItem Value="501">501</asp:ListItem>
                            <asp:ListItem Value="502">502</asp:ListItem>
                            <asp:ListItem Value="503">503</asp:ListItem>
                            <asp:ListItem Value="504">504</asp:ListItem>
                            <asp:ListItem Value="505">505</asp:ListItem>
                            <asp:ListItem Value="601">601</asp:ListItem>
                            <asp:ListItem Value="602">602</asp:ListItem>
                            <asp:ListItem Value="603">603</asp:ListItem>
                            <asp:ListItem Value="604">604</asp:ListItem>
                            <asp:ListItem Value="605">605</asp:ListItem>
                            <asp:ListItem Value="606">606</asp:ListItem>
                            <asp:ListItem Value="607">607</asp:ListItem>
                            <asp:ListItem Value="701">701</asp:ListItem>
                            <asp:ListItem Value="702">702</asp:ListItem>
                            <asp:ListItem Value="703">703</asp:ListItem>
                            <asp:ListItem Value="704">704</asp:ListItem>
                            <asp:ListItem Value="705">705</asp:ListItem>
                            <asp:ListItem Value="706">706</asp:ListItem>
                            <asp:ListItem Value="707">707</asp:ListItem>
                        </asp:DropDownList></td>

Can anybody see what I'm missing? And does anybody know where to find a good tutorial to understand how to read the Stack Trace?

Thanks in advance for any help you can provide....
 
Fixed it...

In all dropdownlists, turn the Selected Value setting to False...

Apparently, if that value is set to true, it sets the dropdownlist value to NULL which then throws an exception, saying the dropdownlist's initial value is NULL, even if you haven't put a NULL, blank, or anything like that in the item list....
 
Back
Top