Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   SelectedValue which is invalid because it does not exist in the list of items. (http://www.velocityreviews.com/forums/t293077-selectedvalue-which-is-invalid-because-it-does-not-exist-in-the-list-of-items.html)

far 05-16-2006 01:10 PM

SelectedValue which is invalid because it does not exist in the list of items.
 
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>

garylamj 08-01-2006 03:59 PM

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

mwrisner 12-27-2007 05:37 PM

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!!

shaileshakgec 12-29-2007 05:36 AM

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.

bartekm 08-17-2008 04:14 AM

Solution
 
Hi,

While you should make sure that your data structure minimises the occurance of this situation, there are situations where it is unavoidable.

I've detailed a solution which basically checks your data before binding the dropdownlist here:

http://blog.evonet.com.au/post/2008/...-of-items.aspx

Cheers,
Bartek

antonacheradu 01-14-2012 05:47 PM

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.


All times are GMT. The time now is 01:47 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57