Friends being a newbie in asp.net I have been layin my hands on this problem for quiet sometime now...hope I find my answer here..
First things first..
I have a gridview which is bound to a SQLDatasource1.In the gridview we have two dropdown(dropdownlist1 and dropdownlist2) Template fields.
Now one of the template field is bound to a datasource SQL datasource2 while the other contains a list of data hardcoded.
Now my requirement is to update the datasource bound to the gridview with the data selectd with the dropdownlist.
Now the dropdownlist is bound to a column called vendorname contained in vendormaster table.
The gridview is bound to a table called request which also contains a column called vendorname..however this column is empty..ie has no data in any row..simply ' '.........
My requirement is to b able to update the request table by selecting values from the two dropdownlist in the gridview..instead i end up with this error...
"'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items"
After going thru a few posts I understand that its due "no values" present in the "request" table for "vendormaster" column.
I then tried hardcodin the values for dropdownlist1 as i have for dropdownlist2..Interesting it now gives the same error for dropdownlist2....
when i removed dropdownlist2 from the gridview things work abs fine....but guys I need to have both the dropdownlist and above that I need to bind my dropdwnlist1 to a datasource.......
How do I accomplish this update....any help wll b highly apreciated..here is the part my code.......
Here is an example of a dropdown list from one of my sites that has it's selection values populated from 1 datasource but it's SelectValue is bound to another.
This is quite a problem if you have not maintained data integrity, and/or if your Select statment in your dropdownlist data source does not include particular values.
Plz have a look at this article and amend your datasource to have a valid datasets.
I get this same error but the URL Link provided does not help with my scenerio. When I go to edit bindings form my user control The Binding for visible fields are "greyed out" including the two-way databinding.
I have a form view edit item template. I have a user control that makes up two dropdownlists. The user control has two properties that return the slected value.
Cany anyone provide some insight on how to do this through the source code?
I too get this error - my data set IS valid and frustratingly it works sometimes (!)
I have found redoing the dropdownlist on the page sometimes corrects the problem, as occasionally does refreshing the schema, but I am trying to complete a form with 6 of these on and it's like juggling plates - am I doing something wrong? why does it seem
so flaky?
Sorry to not offer insight just saying I've got the same problem...
It works "sometimes" because it can find the value both in the dropdownlist and the table your are binding your details view or form view to.
Let's say you have a dropdownlist with numbers 1 - 9. Then your form view or details view is bound to the data table so you can have the "selected value" displayed when you edit a record. When you view various records some have 1 - 9 in the data table and
it can find the value in the dropdownlist and show it as the selected value. Lets say the next record has a 10 or a 0 or is Null, then it can't find a value to show as selected.
I think MS assumes that all db have referential integrity. There are many legacy databases that are not perfect.
So really there are two ways to get by this issue that I've found in the past few week. Either clean up your data in the database and fix all the relationship's or use a user control for the dropdownlist in your application. See this thread for more help
with the user control. http://forums.asp.net/thread/1518715.aspx
I've recently come to asp.2 from 1.1 and am still finding my way. I'm getting the same problem 'dropdownlist has a selected value which is invalid' problem. I have basically added a yes and no text value with corresponding 1 and 0 values to the dropdown
list. i've bound the value field to the datasource to reflect a binary column field. I'm sorry but i just do not see why this will not work as the value very clearly exists in the list. any ideas on this?
Check to make sure that data table doesn't have blank or null values. All records in the data table should have a 1 or a 0 in the column bound to the drop down.
Whether you think you can or you think you can't; you're right.
If Heaven ain't a lot like Detroit, then I don't wanna go... - Uncle Cracker
brazen
Member
6 Points
24 Posts
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of ite...
Dec 22, 2006 10:36 AM|LINK
Friends being a newbie in asp.net I have been layin my hands on this problem for quiet sometime now...hope I find my answer here..
First things first..
I have a gridview which is bound to a SQLDatasource1.In the gridview we have two dropdown(dropdownlist1 and dropdownlist2) Template fields.
Now one of the template field is bound to a datasource SQL datasource2 while the other contains a list of data hardcoded.
Now my requirement is to update the datasource bound to the gridview with the data selectd with the dropdownlist.
Now the dropdownlist is bound to a column called vendorname contained in vendormaster table.
The gridview is bound to a table called request which also contains a column called vendorname..however this column is empty..ie has no data in any row..simply ' '.........
My requirement is to b able to update the request table by selecting values from the two dropdownlist in the gridview..instead i end up with this error...
"'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items"
After going thru a few posts I understand that its due "no values" present in the "request" table for "vendormaster" column.
I then tried hardcodin the values for dropdownlist1 as i have for dropdownlist2..Interesting it now gives the same error for dropdownlist2....
when i removed dropdownlist2 from the gridview things work abs fine....but guys I need to have both the dropdownlist and above that I need to bind my dropdwnlist1 to a datasource.......
How do I accomplish this update....any help wll b highly apreciated..here is the part my code.......
<
asp:GridView ID="GridView1" runat="server" Style="left: 0px; position: relative; top: -87px" Width="550px" AutoGenerateEditButton="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Height="190px"> <Columns> <asp:BoundField DataField="AssetName" HeaderText="AssetName" SortExpression="AssetName" /> <asp:BoundField DataField="Units" HeaderText="Units" SortExpression="Units" /> <asp:BoundField DataField="RequestDescription" ReadOnly="True" HeaderText="RequestDescription" SortExpression="RequestDescription" /> <asp:TemplateField HeaderText="VendorName"> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" Width="94px"/> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:inventoryConnectionString %>" ' SelectCommand="SELECT [VendorName] FROM [VendorMaster]"></asp:SqlDataSource>
</EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Status"> <EditItemTemplate>'
<asp:DropDownList ID="DropDownList2" runat="server" Style="position: relative" Width="39px" selectedvalue='<%# Bind("Status") %>'>'
<asp:ListItem></asp:ListItem>'
<asp:ListItem Value="A"></asp:ListItem>'
<asp:ListItem Value="P"></asp:ListItem>'
<asp:ListItem Value="D"></asp:ListItem>'
</asp:DropDownList>'
</EditItemTemplate> </asp:TemplateField>
</Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:inventoryConnectionString %>" SelectCommand="SELECT [VendorName] FROM [VendorMaster]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:inventoryConnectionString %>" SelectCommand="SELECT DISTINCT [OrderNumber] FROM [Requisition] WHERE ([Status] <> @Status)"> <SelectParameters> <asp:Parameter DefaultValue="A" Name="Status" Type="String" /> </SelectParameters> </asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:inventoryConnectionString %>" SelectCommand="SELECT [AssetName], [Units], [VendorName], [RequestDescription], [Status] FROM [Requisition] WHERE (([OrderNumber] = @OrderNumber) AND ([Status] <> @Status))" UpdateCommand="UPDATE [Requisition] SET [Units]=@Units,[VendorName]=@VendorName,[Status]=@Status WHERE (([OrderNumber] = @OrderNumber) AND ([AssetName] = @AssetName))"> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" Name="OrderNumber" PropertyName="SelectedValue" Type="Int32" /> <asp:Parameter DefaultValue="A" Name="Status" Type="String" /> </SelectParameters> <UpdateParameters> <asp:ControlParameter ControlID="DropDownList1" Name="OrderNumber" PropertyName="SelectedValue" Type="Int32" />
<asp:Parameter Name="VendorName" ConvertEmptyStringToNull="false" Type="String" /> <asp:Parameter Name="Status" ConvertEmptyStringToNull="false" Type="Char" /> <asp:Parameter Name="AssetName" Type="String" /> <asp:Parameter Name="Units" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>Thanx in advance[:)]
GridView
DetroitJ
Participant
1321 Points
267 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Dec 22, 2006 02:13 PM|LINK
Here is an example of a dropdown list from one of my sites that has it's selection values populated from 1 datasource but it's SelectValue is bound to another.
<
asp:DropDownList ID="ddlPCModel" runat="server" DataSourceID="sqldsPCLookup" DataTextField="Model" DataValueField="Model" SelectedValue='<%# Bind("PCModel") %>'>If Heaven ain't a lot like Detroit, then I don't wanna go... - Uncle Cracker
brazen
Member
6 Points
24 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Dec 23, 2006 04:49 AM|LINK
I tried using the following code..
<
asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" Width="94px" DataSourceID="SqlDataSource3" DataTextField="VendorName" DataValueField="VendorName" SelectedValue='<%# Bind("VendorName") %>'/>still the same problem....
I think this is hapenning due to the empty string values in the Vendorname column that has been bound to the dropdownlist1.....
I need to replace these empty cells with the data selected from the dropdownlist...
Do i need to write some code for gridview_Itemdatabound or gridview_ItemUpdating to tackle this issue....
Thanx...
rexlin
Star
9403 Points
1751 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Dec 25, 2006 06:48 AM|LINK
Hi, brazen:
This is quite a problem if you have not maintained data integrity, and/or if your Select statment in your dropdownlist data source does not include particular values.
Plz have a look at this article and amend your datasource to have a valid datasets.
http://www.wherecanibuyit.co.uk/ASP/advanced_gridview_with_edit_and_insert_part_3.html
Best Regards,
__________________________________________________
Sincerely,
Rex Lin
Microsoft Online Community Support
This posting is provided "AS IS" with on warranties, and confers no rights.
JimAmigo
Member
581 Points
267 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Jan 04, 2007 03:21 PM|LINK
I get this same error but the URL Link provided does not help with my scenerio. When I go to edit bindings form my user control The Binding for visible fields are "greyed out" including the two-way databinding.
I have a form view edit item template. I have a user control that makes up two dropdownlists. The user control has two properties that return the slected value.
Cany anyone provide some insight on how to do this through the source code?
senor
Member
2 Points
1 Post
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Jan 11, 2007 11:27 AM|LINK
I too get this error - my data set IS valid and frustratingly it works sometimes (!)
I have found redoing the dropdownlist on the page sometimes corrects the problem, as occasionally does refreshing the schema, but I am trying to complete a form with 6 of these on and it's like juggling plates - am I doing something wrong? why does it seem so flaky?
Sorry to not offer insight just saying I've got the same problem...
heathers
Member
142 Points
46 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Jan 11, 2007 12:34 PM|LINK
MS and many coders say this is the correct behaviour, to the rest of us normal people its just a stupid pain in the arse that we could do without.
I add a null to the select command eg "select cola, colb from table1 union select null, null"
Or you can populate the ddl via code, this is VB:
Dim strCON As String, sqlCON As SqlConnection
Dim strSQL As String, sqlCOM As SqlCommand, sqlDRD As SqlDataReader
strCON = ConfigurationManager.ConnectionStrings("con_db_TM").ToString
sqlCON = New SqlConnection(strCON)
sqlCON.Open()
strSQL = "select distinct tr_code_sub from dbo.tbl_transactions " & _
"where tr_code = '" & Me.ddlCode.SelectedValue & "'"
sqlCOM = New SqlCommand(strSQL, sqlCON)
sqlDRD = sqlCOM.ExecuteReader
Me.ddlCodeSub.Items.Clear()
Me.ddlCodeSub.Items.Add("")
With sqlDRD
If .HasRows = True Then
While .Read
Me.ddlCodeSub.Items.Add(.Item(0))
End While
End If
End With
sqlDRD.Close()
sqlCON.Close()
JimAmigo
Member
581 Points
267 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Jan 11, 2007 01:59 PM|LINK
It works "sometimes" because it can find the value both in the dropdownlist and the table your are binding your details view or form view to.
Let's say you have a dropdownlist with numbers 1 - 9. Then your form view or details view is bound to the data table so you can have the "selected value" displayed when you edit a record. When you view various records some have 1 - 9 in the data table and it can find the value in the dropdownlist and show it as the selected value. Lets say the next record has a 10 or a 0 or is Null, then it can't find a value to show as selected.
I think MS assumes that all db have referential integrity. There are many legacy databases that are not perfect.
So really there are two ways to get by this issue that I've found in the past few week. Either clean up your data in the database and fix all the relationship's or use a user control for the dropdownlist in your application. See this thread for more help with the user control. http://forums.asp.net/thread/1518715.aspx
Broadwood
Member
2 Points
1 Post
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Apr 18, 2007 08:49 AM|LINK
Hi There
I've recently come to asp.2 from 1.1 and am still finding my way. I'm getting the same problem 'dropdownlist has a selected value which is invalid' problem. I have basically added a yes and no text value with corresponding 1 and 0 values to the dropdown list. i've bound the value field to the datasource to reflect a binary column field. I'm sorry but i just do not see why this will not work as the value very clearly exists in the list. any ideas on this?
Nick Wood
www.broadwoodmusic.co.uk
DetroitJ
Participant
1321 Points
267 Posts
Re: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of...
Apr 18, 2007 01:45 PM|LINK
If Heaven ain't a lot like Detroit, then I don't wanna go... - Uncle Cracker