'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?
 
Juan_BarreraConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.