None of them mentioning any workaround to get this to work
But still as soon as i hit the "Edit" buton on my gridview i get the "'DDL2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
Exception Details: System.ArgumentOutOfRangeException: 'DDL2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
the data exists for sure and there is no null values
Oprhan, one thing to check would be the size and type of fields in the table that has your drop down options and the table that is supposed to store the resulting selection--they have to be exactly the same or else you will get this message.
That's what caused my problem, one was 2 character, the other was 3--a typo on my part, they were both supposed to be 2. Once I corrected this everything worked fine--it's an awful error message that .NET gives you because it makes you think you've got
a bad field name or null data which is what everyone tells you to check (all well-meaning people to be sure, but when I explicitly stated I had no null or blank fields--I only had 5 recs in the DB, I could open it in SQL Server Manager and instantly verify
there were no null fields--and everyone kept suggesting the same thing it was frustrating).
I wrestled with this one also and it had to do with null values in the db. The db column is of type 'int', so I made sure that there are no null values in the column, rather the default value is 0. Also, I made sure that there was no value for 0 in the
ref table that I was querying for the match.
Now when the ddl loads, it defaults to "Please Select" if there is no recorded value.
again, same problem as everyone here. Unfortunately none of the solutions from this thread seem to work in my scenario! Which is kind of a pain because I've been fighting with a simple gridview for a few days now! I have a dropdown in the gridview which
selects someones name, and the value is their particular sequence which is found in the query where the data comes from. This "sequence" is then used with other data used in that row to insert into a table. This problem just wont go away.
I have created a page that runs the same query to return ID (their sequence), name and code (like a login), and then on changing the ddl a label returns the value. It worked fine, as it should for example, Me (in the db) = 1193 and so on.
I think i'm having some miss match between data trying to be stored and what the records actually holding (eg trying to store sequence into the wrong column or something) but nothing works and nothing appears to contain something that could cause such an
error? This is extremely frustrating!
orphan
Member
9 Points
3 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Sep 11, 2008 08:18 PM|LINK
I Too have the same problem
Is this a verfied bug in .NET?
Im trying to follow that Tutorials both on here http://www.asp.net/learn/data-access/tutorial-20-cs.aspx and on msdn http://msdn.microsoft.com/en-us/library/bb426884.aspx
None of them mentioning any workaround to get this to work
But still as soon as i hit the "Edit" buton on my gridview i get the "'DDL2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value"
Exception Details: System.ArgumentOutOfRangeException: 'DDL2' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
the data exists for sure and there is no null values
acmassie
Member
29 Points
12 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Sep 11, 2008 08:47 PM|LINK
Oprhan, one thing to check would be the size and type of fields in the table that has your drop down options and the table that is supposed to store the resulting selection--they have to be exactly the same or else you will get this message.
That's what caused my problem, one was 2 character, the other was 3--a typo on my part, they were both supposed to be 2. Once I corrected this everything worked fine--it's an awful error message that .NET gives you because it makes you think you've got a bad field name or null data which is what everyone tells you to check (all well-meaning people to be sure, but when I explicitly stated I had no null or blank fields--I only had 5 recs in the DB, I could open it in SQL Server Manager and instantly verify there were no null fields--and everyone kept suggesting the same thing it was frustrating).
orphan
Member
9 Points
3 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Sep 12, 2008 07:04 AM|LINK
thx for your answer acmassie
Not sure if I understand you rightm but its just a integer value.
Im picking up a ID from one table, trying to add it to the other table, as a realtion reference
It "works" if I unchek the "Two-way Binding" but then ofcourse the field will have null for value
dropdown datalist
johnnyRoyale
Member
4 Points
4 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Oct 17, 2008 11:39 AM|LINK
Cheers cosmin.onea! AppendDataBoundItems was exaclty the kind of thing I was looking for!
mdixon
Member
4 Points
5 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Oct 29, 2008 07:30 PM|LINK
Note that the "DEFAULTVALUE", is a value that is known to exist in the table used to populate the
drop-down. Could have statically populated the drop down, but then would have to manually update the code each time the
available selection list changes.
protected void OnDataBinding_ddlApptype(object sender, EventArgs e){
DropDownList ddl = (DropDownList)sender;if (ddl != null){
if (ddl.SelectedValue == null || ddl.SelectedValue == "") ddl.SelectedValue = "DEFAULTVALUE";}
}
.Net 2.0 .Net 2.0 FormView
hlp4al
Member
371 Points
86 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Nov 03, 2008 06:08 AM|LINK
Hi..
I faced the same problem, but i fixed this as below..
One thing you have to observe: i.e binding column should not have null values. There should not any scope to save the blank field in that column..
for example:
this is dropdownlist in gridview
<asp:DropDownList ID="DropDownList4" runat="server" Enabled =true
SelectedValue='<%# Bind("WORKTYPE") %>' AppendDataBoundItems =true>
<asp:ListItem Value="PR">Processing</asp:ListItem>
<asp:ListItem Value="QC">Quality Checking</asp:ListItem>
<asp:ListItem Value="Both">Both</asp:ListItem>
</asp:DropDownList>
the WorkType column is CHAR(10)
while saving PR in that WorkType column, it occupies only 2 bits of space, remaining 8 bits of space occupies null values/Spaces..
so it is not matching with the dropdownlist PR value.. Because of that reason we got that error..
More concentrate on this.. Remove the error and Happy Coding..
Thanks and Regards
hlp4al..
cheryl01
Member
8 Points
25 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Nov 30, 2008 07:13 PM|LINK
I would like to try this.. Can you translate this to VB?
Thanks!
skiah
Member
85 Points
48 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Dec 24, 2008 01:33 PM|LINK
I wrestled with this one also and it had to do with null values in the db. The db column is of type 'int', so I made sure that there are no null values in the column, rather the default value is 0. Also, I made sure that there was no value for 0 in the ref table that I was querying for the match.
Now when the ddl loads, it defaults to "Please Select" if there is no recorded value.
<asp:TemplateField HeaderText="Surgical Subspecialty" > <ItemTemplate> <asp:dropdownlist ID="ddlSubElectives" SelectedValue='<%# Bind("surgicalsubspecialty") %>' DataTextField="elective_name" DataValueField="elective_id" Enabled="false" runat="server" AppendDataBoundItems="True" datasourceid="sdsSubElectives"> <asp:ListItem Value="0">Please Select</asp:ListItem> </asp:dropdownlist> </ItemTemplate> <EditItemTemplate> <asp:dropdownlist ID="ddlSubElectivesEdit" SelectedValue='<%# Bind("surgicalsubspecialty") %>' DataTextField="elective_name" DataValueField="elective_id" runat="server" AppendDataBoundItems="True" datasourceid="sdsSubElectives"> <asp:ListItem Value="0">Please Select</asp:ListItem> </asp:dropdownlist> </EditItemTemplate> </asp:TemplateField>NayC
Member
17 Points
41 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Apr 20, 2009 01:41 PM|LINK
HI,
again, same problem as everyone here. Unfortunately none of the solutions from this thread seem to work in my scenario! Which is kind of a pain because I've been fighting with a simple gridview for a few days now! I have a dropdown in the gridview which selects someones name, and the value is their particular sequence which is found in the query where the data comes from. This "sequence" is then used with other data used in that row to insert into a table. This problem just wont go away.
I have created a page that runs the same query to return ID (their sequence), name and code (like a login), and then on changing the ddl a label returns the value. It worked fine, as it should for example, Me (in the db) = 1193 and so on.
I think i'm having some miss match between data trying to be stored and what the records actually holding (eg trying to store sequence into the wrong column or something) but nothing works and nothing appears to contain something that could cause such an error? This is extremely frustrating!
ajith_tintin
Member
6 Points
3 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
May 13, 2009 08:54 AM|LINK
hey friends!!!
here