1

I am a complete newb to webapps but here goes.

I have web form with a drop-down list that populates a list of holiday resorts from a database procedure. That bit works fine. When I select an item from the list I need to populate a listbox with hotels specific to that resort.

This bit I am having trouble with, the list does populate if I click off the drop-down list onto a calendar control on the form.

Question: how do I get it to populate the list after I clcik on the value from the drop-down list?

Thanks

Here is the code by the way:

Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
    Me.Calendar1.SelectedDate = Now()


    Me.DropDownList1.Items.Clear()

    Dim connStr As String = Web.Configuration.WebConfigurationManager.ConnectionStrings("ITC").ConnectionString
    Dim conn As New SqlClient.SqlConnection(connStr)
    conn.Open()

    Dim sqlProducts As String = "<<sql_string>>"

    Dim da As New SqlDataAdapter(sqlProducts, conn)
    Dim ds As New DataSet()
    da.Fill(ds, "Products")

    DropDownList1.DataTextField = "Rcode"
    DropDownList1.DataValueField = "Rcode"
    DropDownList1.DataSource = ds.Tables("Products")
    DropDownList1.DataBind()

    ds.Dispose()
    da.Dispose()

    conn.Close()

End Sub

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged

    Me.ListBox1.Items.Clear()
    Me.ListBox2.Items.Clear()

    Dim connStr As String = WebConfigurationManager.ConnectionStrings("ITC").ConnectionString
    Dim conn As New SqlConnection(connStr)
    conn.Open()

    Dim sqlProducts As String = "sql_string '" & Me.DropDownList1.Text & "'"

    Dim da As New SqlDataAdapter(sqlProducts, conn)
    Dim ds As New DataSet()
    da.Fill(ds, "Products")

    ListBox1.DataTextField = "accommDescription"
    ListBox1.DataValueField = "accommCode"
    ListBox1.DataSource = ds.Tables("Products")
    ListBox1.DataBind()

    ds.Dispose()
    da.Dispose()
    conn.Close()

    ListBox1.Focus()

End Sub

0 Answers0