gregburningham
Programmer
Hi all
I am having trouble doing a simple task - whilst I have managed to bind a simple drop-down list from a query in other .NET apps I have written, I have not managed to do it in a class using array lists ....
This almost works but for some reason I cannot assign the values of "code" to the dropdown list ?
PLEASE CAN YOU HELP .... !!!! Thanks Greg B
Public Sub BuildArrayList(ByVal blankLine As Boolean, ByVal oraConnectionStr As String, ByVal sqlStr As String _
, ByVal vDropDownList As DropDownList, ByVal listValue As String)
' attempt to pass in and return the ListItem Object itself
Dim newArrayList As New ArrayList()
Dim newArrayListValue As New ArrayList()
' Dim newArrayList As MyArrayList
Dim createArrayException As Exception
Dim createArrayListCommand As New OleDb.OleDbCommand()
Dim oraConnection As New OleDb.OleDbConnection()
Dim arrayListDataReader As OleDb.OleDbDataReader
Try
'Get the Oracle connection string.
oraConnection.ConnectionString = oraConnectionStr
createArrayListCommand.Connection = oraConnection
'Open the Oracle connection.
oraConnection.Open()
'Build the Status LOV from a SQL statement.
createArrayListCommand.CommandText = sqlStr
createArrayListCommand.CommandType = CommandType.Text
arrayListDataReader = createArrayListCommand.ExecuteReader()
'Add a blank line to the array list if required.
If blankLine = True Then
newArrayList.Add(""
End If
While arrayListDataReader.Read
newArrayList.Add(arrayListDataReader.Item("code_desc"
)
newArrayListValue.Add(arrayListDataReader.Item("code"
)
End While
arrayListDataReader.Close()
vDropDownList.DataSource = newArrayList
vDropDownList.DataBind()
' set item selected
If listValue = "" Then
listValue = newArrayListValue.Item(0)
End If
Dim itemCount As Integer
For itemCount = 0 To newArrayListValue.Count - 1
vDropDownList.Items(itemCount).Selected = False
If newArrayListValue(itemCount) = listValue Then
vDropDownList.Items(itemCount).Selected = True
End If
vDropDownList.Items(itemCount).Value = newArrayListValue(itemCount)
Next
Catch createarrayException
exceptionMessageStr = createArrayException.Message.ToString()
Finally
'Close the Oracle connection.
oraConnection.Close()
End Try
End Sub
I am having trouble doing a simple task - whilst I have managed to bind a simple drop-down list from a query in other .NET apps I have written, I have not managed to do it in a class using array lists ....
This almost works but for some reason I cannot assign the values of "code" to the dropdown list ?
PLEASE CAN YOU HELP .... !!!! Thanks Greg B
Public Sub BuildArrayList(ByVal blankLine As Boolean, ByVal oraConnectionStr As String, ByVal sqlStr As String _
, ByVal vDropDownList As DropDownList, ByVal listValue As String)
' attempt to pass in and return the ListItem Object itself
Dim newArrayList As New ArrayList()
Dim newArrayListValue As New ArrayList()
' Dim newArrayList As MyArrayList
Dim createArrayException As Exception
Dim createArrayListCommand As New OleDb.OleDbCommand()
Dim oraConnection As New OleDb.OleDbConnection()
Dim arrayListDataReader As OleDb.OleDbDataReader
Try
'Get the Oracle connection string.
oraConnection.ConnectionString = oraConnectionStr
createArrayListCommand.Connection = oraConnection
'Open the Oracle connection.
oraConnection.Open()
'Build the Status LOV from a SQL statement.
createArrayListCommand.CommandText = sqlStr
createArrayListCommand.CommandType = CommandType.Text
arrayListDataReader = createArrayListCommand.ExecuteReader()
'Add a blank line to the array list if required.
If blankLine = True Then
newArrayList.Add(""
End If
While arrayListDataReader.Read
newArrayList.Add(arrayListDataReader.Item("code_desc"
newArrayListValue.Add(arrayListDataReader.Item("code"
End While
arrayListDataReader.Close()
vDropDownList.DataSource = newArrayList
vDropDownList.DataBind()
' set item selected
If listValue = "" Then
listValue = newArrayListValue.Item(0)
End If
Dim itemCount As Integer
For itemCount = 0 To newArrayListValue.Count - 1
vDropDownList.Items(itemCount).Selected = False
If newArrayListValue(itemCount) = listValue Then
vDropDownList.Items(itemCount).Selected = True
End If
vDropDownList.Items(itemCount).Value = newArrayListValue(itemCount)
Next
Catch createarrayException
exceptionMessageStr = createArrayException.Message.ToString()
Finally
'Close the Oracle connection.
oraConnection.Close()
End Try
End Sub