Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2006, 05:47 PM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

 
Old April 20th, 2006, 11:14 AM
Registered User
 
Join Date: Feb 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's ok... I figured it out.
Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating web form with drop down list selection AugieDawgie ASP.NET 1.0 and 1.1 Basics 0 December 7th, 2005 11:44 AM
populating a drop down with a file list cjcd ASP.NET 1.0 and 1.1 Professional 2 April 18th, 2004 10:37 AM
populating a drop down with a file list cjcd BOOK: Beginning ASP.NET 1.0 1 April 17th, 2004 02:53 AM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.