Hi everyone,
I have a few multi-select list boxes on my asp.net page. The information needs to be sent back to the server to be stored in a database.
One list contains geographical regions:
North America
Europe
Africa
Asia
My code needs to convert this into a string to be sent to the DB. For example, if the user selects "Europe", the string "Europe" needs to go back. If they select Europe and Africa, then the string "Europe Africa" needs to go back. I have the following function that is supposed to create this string:
Private Function BuildListString(ByVal ctl As ListBox) As String
'Purpose
'Create a string from a multi-select list box
Dim str As String
Dim i As Integer
Try
'create the string
For i = 0 To ctl.Items.Count
If ctl.Items(i).Selected = True Then
If i = 0 Then
str = ctl.Items(i).Value
Else
str = str & " " & ctl.Items(i).Value
End If
End If
Next
Catch
End Try
End Function
The form has a few multi-select lists like the one described above, so I want to be able to pass the control to the function and re-use the code.
When I run the code, .net returns the error "Referenced object has a value of 'Nothing'."
Any ideas? Is it possible to do this?
Thanks
Peter
I have a few multi-select list boxes on my asp.net page. The information needs to be sent back to the server to be stored in a database.
One list contains geographical regions:
North America
Europe
Africa
Asia
My code needs to convert this into a string to be sent to the DB. For example, if the user selects "Europe", the string "Europe" needs to go back. If they select Europe and Africa, then the string "Europe Africa" needs to go back. I have the following function that is supposed to create this string:
Private Function BuildListString(ByVal ctl As ListBox) As String
'Purpose
'Create a string from a multi-select list box
Dim str As String
Dim i As Integer
Try
'create the string
For i = 0 To ctl.Items.Count
If ctl.Items(i).Selected = True Then
If i = 0 Then
str = ctl.Items(i).Value
Else
str = str & " " & ctl.Items(i).Value
End If
End If
Next
Catch
End Try
End Function
The form has a few multi-select lists like the one described above, so I want to be able to pass the control to the function and re-use the code.
When I run the code, .net returns the error "Referenced object has a value of 'Nothing'."
Any ideas? Is it possible to do this?
Thanks
Peter