![]() |
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> |
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 |
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!! |
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.
|
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 |
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.