'DropDownList8' has a SelectedValue which is invalid because it does not exist in the list of items.

Hi;

I have been trying to solve this for too long I need another pair of eyes to see what I am missing in my code.

An ASP page had been working until I upgraed the data the page is based on to SQL 2K.

When I try an edit a DDL column in a  row in my page's grid view I  gey thefollowing message.

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

I don't completely understand the question.

What is the ist of items the msg refers to ? The template items or the columns in my select statement ?
I have double checked my template columns and all the Selectedvalue items look correct to me.

And where do I look for Parameter name "Value" ? I don't see this in my code.

If you need this to understand the error message :

ArgumentOutOfRangeException: 'DropDownList8' 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) +1604142
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +107
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.Control.DataBindChildren() +211
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +102
   System.Web.UI.Control.DataBind() +15
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +155
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2417
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e) +22
   System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +17
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842


Thanks
 




<asp:TemplateField HeaderText="Priority" SortExpression="priority">
                    <EditItemTemplate>
                        <asp:DropDownList ID="DropDownList8" runat="server" DataSourceID="ObjectDataSource3"
                            DataTextField="Priority_Name" DataValueField="Priority_Value" SelectedValue='<%# Bind("priority", "{0}") %>'
                             AppendDataBoundItems="True">
                            <asp:ListItem Value="0" Selected="True">Please Select</asp:ListItem> 
                        </asp:DropDownList>

Open in new window

gggoddardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Juan_BarreraCommented:
Hi there,

If you are trying to populate the ddl, you just need to set the DataTextField and the DataValueField properties.
SelectedValue is ReadOnly, and returns the value of the DDL SelectedItem.

Your markup should look like this:

 <asp:DropDownList ID="DropDownList8" runat="server" DataSourceID="ObjectDataSource3"
                            DataTextField="Priority_Name" DataValueField="Priority_Value"
                             AppendDataBoundItems="True">
                            <asp:ListItem Value="0" Selected="True">Please Select</asp:ListItem>
</asp:DropDownList>

In this case, SelectedValue would be 0, as you are explicetly setting the SelectedItem property to "True" on an item wit value 0:

  <asp:ListItem Value="0" Selected="True">Please Select</asp:ListItem>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gggoddardAuthor Commented:
Refresh your template controls for your DDLs too.
I had not done this since I converted my database sources to SQL 2K.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.