SelectedValue which is invalid because it does not exist in the list of items.

far

Joined
May 16, 2006
Messages
1
Reaction score
0
Hello,

Especially Phillip. I am desparately trying to implement cascading dropdowns with in a gridview. However I can not even get past the basics.

Here is the error I get. I am using the pubs database.
'ddlCountry' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Please advise. Thanks, far

Here is my code:

<asp:ObjectDataSource ID="odsPublishers" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetPublishers" TypeName="PubsTableAdapters.PublishersTableAdapter"></asp:ObjectDataSource>

</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="odsPublishers" AllowPaging="True" AllowSorting="True" DataKeyNames="pub_id">
<Columns>
<asp:TemplateField HeaderText="Commands">
<ItemTemplate>
<asp:LinkButton CommandName="Edit" ID="btnEdit" runat="server" Text="Edit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton CommandName="Update" ID="btnUpdate" runat="server" Text="Update"></asp:LinkButton>
<asp:LinkButton CommandName="Cancel" ID="btnCancel" runat="server" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>


<asp:BoundField DataField="pub_id" HeaderText="pub_id" ReadOnly="True" SortExpression="pub_id" />
<asp:BoundField DataField="pub_name" HeaderText="pub_name" SortExpression="pub_name" />

<asp:BoundField DataField="country" HeaderText="country" SortExpression="country" />
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Text='<%#Eval("Country") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:ObjectDataSource ID="odsCountry" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetCountry" TypeName="PubsTableAdapters.pubCountryTableAdapter"></asp:ObjectDataSource>
<asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountry" AutoPostBack="True"
SelectedValue='<%# Bind("Country") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="state" HeaderText="state" SortExpression="state" />
</Columns>
</asp:GridView>
 
Joined
Aug 1, 2006
Messages
1
Reaction score
0
I have gone throught that problem as well.

just simply do something like this:

<asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountries"
AutoPostBack="True"
SelectedValue='<%# Bind("Country") %>'
AppendDataBoundItems="true">
<asp:ListItem Value="">Select a Country</asp:ListItem>
<asp:ListItem Value="">Your invalid data</asp:ListItem>
<asp:ListItem Value="">Your invalid data</asp:ListItem>
</asp:DropDownList>

OR

Fix up your database don't allow nulls.

However, I need your help.

I do the same things but whatever my dropdown value is chosen, it won't update my database. Can you suggest me a solution why?

Thanks,
Gary
 
Joined
Dec 27, 2007
Messages
1
Reaction score
0
Try This!

When I had this error message, it drove me nuts for solid day! Here's what I learned:

If you're receiving this error, then an Eval("something") or Bind("something") is referencing a database column that is empty. Manually enter some data (using SQL Server Management Studio, perhaps), and see if the error doesn't go away.\

Hope this helps. Good luck!!
 
Joined
Dec 29, 2007
Messages
1
Reaction score
0
Call only once

I got same problem too. I had used a function to Bind drop down list. But i got that i was calling that function two times and i think due to calling two times, i was facing that error. Then i call that function only once and error resolved. If any one got better option then pls reply.
 
Joined
Jan 14, 2012
Messages
1
Reaction score
0
Try to add an UNION at your SQL SELECT phrase which populate your DropDownList:
SELECT GroupeID, Groupe FROM [Groupe]
union select '', ''

This will give you an empty row for avoiding the error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top