I have a drop down list that get the values from the database allows the user to select a value and then based on that value populates another drop down list with other values from the database.
My problem is when the first item in the lists is selected it will not populate the next drop down list. How do I fix this.
Here is my code:
My problem is when the first item in the lists is selected it will not populate the next drop down list. How do I fix this.
Here is my code:
Visual Basic:
On Error GoTo Error_Handler
Dim pRS As New ADODB.Recordset
Dim psTemp As String
Dim psSQL As String = "SELECT PROG_ID, PROG_DESCR "
Dim psFrom As String = "FROM PROGRAM_VW"
Dim psWhere As String = vbNullString
Dim psOrder As String = "ORDER BY PROG_DESCR"
Dim piIndex As Integer = 0
Dim pbItemSelected As Boolean = False
psTemp = psSQL & Chr(32) & psFrom & Chr(32) & psWhere & Chr(32) & psOrder
'** Open the Recordset using the HMS database **'
pRS = eJDS.Global.GetOracleRecordset("JDS", psTemp, Session)
If pRS Is Nothing Then
'** Indicate no records found **'
lblHeader.Text = "No Items to Select - Select Cancel or Back"
cboProgram.Items.Add(New ListItem("No Items to Select - Select Cancel or Back"))
' btnSubmit.Visible = False
GoTo Sub_Exit
End If
With pRS
If .RecordCount <> 0 Then
'** Clear the list box **'
cboProgram.Items.Clear()
'** Move to the first record in the recordset **'
.MoveFirst()
'** Loop through records until the end of the file is reached **'
Do While Not .EOF
'** Add the report name **'
cboProgram.Items.Add(New ListItem(.Fields("PROG_DESCR").Value, .Fields("PROG_ID").Value))
.MoveNext()
'** Increment the counter **'
piIndex = piIndex + 1
Loop
'** Close the recordset **'
pRS.Close()
'** Show the list box **'
cboProgram.Visible = True
Else
'** Indicate no records found **'
NoRecs()
GoTo Sub_Exit
End If
End With
'** Do this the first time the page is loaded only **'
If Not IsPostBack Then
'** Select the item in the list, if it has previously been selected **'
If cboProgram.Items.Count > 0 And (Not pbItemSelected) Then
'** Select the first item in the list be default **'
cboProgram.Items(0).Selected = True
End If
End If
Sub_Exit:
pRS = Nothing
Exit Sub
Error_Handler:
'** Set the global error message variable **'
Session("ErrorMessage") = "" & _
"The following error occured during " & _
Session("msModule") & " LoadProgramList Event." & _
vbCrLf & vbCrLf & _
Err.Number & vbTab & Err.Description
Response.Redirect("frmError.aspx")
Err.Clear()
GoTo Sub_Exit
End Sub
Last edited by a moderator: