Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 03, 2010 10:03 PM by alkurta
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.......
Thanx in advance[:)]
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.
Dec 23, 2006 04:49 AM|LINK
I tried using the following code..
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....
Dec 25, 2006 06:48 AM|LINK
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.
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?
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
Sorry to not offer insight just saying I've got the same problem...
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)
strSQL = "select distinct tr_code_sub from dbo.tbl_transactions " & _
"where tr_code = '" & Me.ddlCode.SelectedValue & "'"
sqlCOM = New SqlCommand(strSQL, sqlCON)
sqlDRD = sqlCOM.ExecuteReader
If .HasRows = True Then
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
Apr 18, 2007 08:49 AM|LINK
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?
Apr 18, 2007 01:45 PM|LINK