Hi,
I'm successfully populating a drop down list from an ArrayList that I've in turn populated from a SQL DB using a reader.
Here's my code:
Code:
Public Function PopulateModuleDropDown() As ArrayList
'declare variables
Dim arrModules As New ArrayList
Dim strSqlStatement As String = "SELECT ModuleName From Modules"
Dim cmdPMDD As New SqlCommand(strSqlStatement, nurseConnection)
cmdPMDD.CommandType = CommandType.Text
Dim drPMDD As SqlDataReader
Try
'open connection to the database
nurseConnection.Open()
'execute reader, then close the connection
drPMDD = cmdPMDD.ExecuteReader(CommandBehavior.CloseConnection)
While drPMDD.Read()
arrModules.Add(drPMDD("ModuleName"))
End While
'drPMDD.Close()
Return arrModules
Catch ex As Exception
ex.ToString()
End Try
End Function
My problem is that because the ArrayList is 0-based, when I choose an option from the drop down list, the results are always off by 1.
Again, my code:
Code:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
'For each question in the SQL DB, create a label and insert the question into it
Dim dsAQ As DataSet = DA.QuestionsDataSet(ddlModule.SelectedIndex)
Dim i As Integer = 0
Dim strTest As String
Dim strQuestionText As String
Do While i <= dsAQ.Tables(0).Rows.Count - 1
strQuestionText = dsAQ.Tables(0).Rows(i).Item("Question")
'If strQuestionText <> strTest Then
'strTest = strQuestionText
Dim lblQuestion As New Label
lblPlaceHolder.Controls.Add(lblQuestion)
lblQuestion.Text = strQuestionText
'End If
i += 1
Loop
End Sub
So in other words, say the user chooses the second item in the ddl, "Module Two". The code in the button_click event should return text related to Module Two, but returns text related to Module One instead. How do I fix this? It must be a simple fix, but I'm flying blind.
Thanks in advance for any help!
Jens