Error in dropdownlist binding
-
i have created drop downdownlist and i m binding it with the testnames in the database.
Private Function load_sptestreqtestnameddl()
Dim Adptr As New SqlDataAdapter Dim Pkgddldt As New DataSet '################## FOR CONNECTION ################ Dim MySearchCon As DbConnection = providerFactory.CreateConnection() MySearchCon.ConnectionString = connectionString.ConnectionString '################### END OF CONNECTION ################# Dim str As String = Nothing str = ("SELECT test\_id, test\_name FROM TestName") Adptr = New SqlDataAdapter(str, MySearchCon) Adptr.Fill(Pkgddldt) sptestreqtestnameddl.DataSource = Pkgddldt sptestreqtestnameddl.DataSource = Pkgddldt.Tables(0) sptestreqtestnameddl.DataTextField = Pkgddldt.Tables(0).Columns("test\_name").ColumnName.ToString sptestreqtestnameddl.DataValueField = Pkgddldt.Tables(0).Columns("test\_id").ColumnName.ToString
sptestreqtestnameddl.DataBind()
Return 0
End subthe code shows me following error....this exactly same code works perfect in other webforms. 'sptestreqtestnameddl' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
-
i have created drop downdownlist and i m binding it with the testnames in the database.
Private Function load_sptestreqtestnameddl()
Dim Adptr As New SqlDataAdapter Dim Pkgddldt As New DataSet '################## FOR CONNECTION ################ Dim MySearchCon As DbConnection = providerFactory.CreateConnection() MySearchCon.ConnectionString = connectionString.ConnectionString '################### END OF CONNECTION ################# Dim str As String = Nothing str = ("SELECT test\_id, test\_name FROM TestName") Adptr = New SqlDataAdapter(str, MySearchCon) Adptr.Fill(Pkgddldt) sptestreqtestnameddl.DataSource = Pkgddldt sptestreqtestnameddl.DataSource = Pkgddldt.Tables(0) sptestreqtestnameddl.DataTextField = Pkgddldt.Tables(0).Columns("test\_name").ColumnName.ToString sptestreqtestnameddl.DataValueField = Pkgddldt.Tables(0).Columns("test\_id").ColumnName.ToString
sptestreqtestnameddl.DataBind()
Return 0
End subthe code shows me following error....this exactly same code works perfect in other webforms. 'sptestreqtestnameddl' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
hi, After filling the data adapter, please clear the dropdown then try to bind.
sptestreqtestnameddl.Items.Clear();
Seems to me after binding list, dropdown tries to select a value that is not even in the dropdown list. Thnaks
-
i have created drop downdownlist and i m binding it with the testnames in the database.
Private Function load_sptestreqtestnameddl()
Dim Adptr As New SqlDataAdapter Dim Pkgddldt As New DataSet '################## FOR CONNECTION ################ Dim MySearchCon As DbConnection = providerFactory.CreateConnection() MySearchCon.ConnectionString = connectionString.ConnectionString '################### END OF CONNECTION ################# Dim str As String = Nothing str = ("SELECT test\_id, test\_name FROM TestName") Adptr = New SqlDataAdapter(str, MySearchCon) Adptr.Fill(Pkgddldt) sptestreqtestnameddl.DataSource = Pkgddldt sptestreqtestnameddl.DataSource = Pkgddldt.Tables(0) sptestreqtestnameddl.DataTextField = Pkgddldt.Tables(0).Columns("test\_name").ColumnName.ToString sptestreqtestnameddl.DataValueField = Pkgddldt.Tables(0).Columns("test\_id").ColumnName.ToString
sptestreqtestnameddl.DataBind()
Return 0
End subthe code shows me following error....this exactly same code works perfect in other webforms. 'sptestreqtestnameddl' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
Just specify columns in DataTextField and DataValueField like this:
sptestreqtestnameddl.DataTextField = "test_name"
sptestreqtestnameddl.DataValueField = "test_id"
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com