G
Guest
Hmm, nobody seems to want to answer any of my questions, but here goes again!
I have a Detailview control that is bound to a data source. Within the
Detailview control I have a number of dropdownlist controls that I want to
list available options but will be bound to the Detailview control. I can
achieve all this and seem to select the correct item from the datasource.
However, when I try to update, the bound dropdownlist value seems to be
missing and I get a db error saying cannot enter a null value. I have tried a
number of ways to achieve this by declaring on a page and now I am using code
behind to define & construct the dropdownlist items. Any help would be great
as I am beginning to suspect that old style ASP was a much better solution!..
Private Sub testbind(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList
ddl = sender
ddl.ClearSelection()
ddl.DataSourceID = "SqlDataSource2"
ddl.DataValueField = "Case_Contact_Directorate_ID"
End Sub
Private Sub test2(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList
ddl = sender
Dim con As New
SqlClient.SqlConnection(ConfigurationSettings.ConnectionStrings("AppConnectionString1").ConnectionString)
Dim comm As New SqlClient.SqlCommand("SELECT [Directorate_ID],
[Directorate_Name] FROM [Directorate]", con)
Dim rdr As SqlClient.SqlDataReader
con.Open()
rdr = comm.ExecuteReader
Dim di As ListItem
While rdr.Read
di = New ListItem(rdr(1), rdr(0))
ddl.Items.Add(di)
End While
con.Close()
con = Nothing
comm = Nothing
Dim val As Integer = ddl.Items(0).Value
'di = ddl.Items(0)
'ddl.Items.Remove(di)
'di = Nothing
For Each di In ddl.Items
If di.Value = val Then
di.Selected = True
Exit For
End If
Next
End Sub
I have a Detailview control that is bound to a data source. Within the
Detailview control I have a number of dropdownlist controls that I want to
list available options but will be bound to the Detailview control. I can
achieve all this and seem to select the correct item from the datasource.
However, when I try to update, the bound dropdownlist value seems to be
missing and I get a db error saying cannot enter a null value. I have tried a
number of ways to achieve this by declaring on a page and now I am using code
behind to define & construct the dropdownlist items. Any help would be great
as I am beginning to suspect that old style ASP was a much better solution!..
Private Sub testbind(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList
ddl = sender
ddl.ClearSelection()
ddl.DataSourceID = "SqlDataSource2"
ddl.DataValueField = "Case_Contact_Directorate_ID"
End Sub
Private Sub test2(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl As DropDownList
ddl = sender
Dim con As New
SqlClient.SqlConnection(ConfigurationSettings.ConnectionStrings("AppConnectionString1").ConnectionString)
Dim comm As New SqlClient.SqlCommand("SELECT [Directorate_ID],
[Directorate_Name] FROM [Directorate]", con)
Dim rdr As SqlClient.SqlDataReader
con.Open()
rdr = comm.ExecuteReader
Dim di As ListItem
While rdr.Read
di = New ListItem(rdr(1), rdr(0))
ddl.Items.Add(di)
End While
con.Close()
con = Nothing
comm = Nothing
Dim val As Integer = ddl.Items(0).Value
'di = ddl.Items(0)
'ddl.Items.Remove(di)
'di = Nothing
For Each di In ddl.Items
If di.Value = val Then
di.Selected = True
Exit For
End If
Next
End Sub