dropdownlist - using as a picklist

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
 
P

Patrice

I don't see how the update is done... My first though would be to use the
profiler to see if this is the only field that has a problem or if something
is totally wrong about the update...

You may want also to try first with a single drop donw list to see if it
behaves as expected... (could it works for some but not all of your
dropdownlist).

Do you use ASP.NET 2.0 ?

Patrice
 
G

Guest

Thanks for the reply Patrice,

I am using framework 2.0 and I am trying to carry out the update using the
datasource update and a stored procedure with 14 update params. I need to use
the dropdownlist controls to guarantee the integrity of the data...I am
prepared to code the update but I have so much trouble identifying and
accessing the cells that hold the data, I thought this would be more likely
to succeed!

Patrice said:
I don't see how the update is done... My first though would be to use the
profiler to see if this is the only field that has a problem or if something
is totally wrong about the update...

You may want also to try first with a single drop donw list to see if it
behaves as expected... (could it works for some but not all of your
dropdownlist).

Do you use ASP.NET 2.0 ?

Patrice


--

Paul Owen said:
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("AppConnecti
onString1").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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top