|
|
 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

April 19th, 2006, 06:47 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Populating a drop down list from an ArrayList
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
|

April 20th, 2006, 12:14 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It's ok... I figured it out.
Thanks
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |