Drop-down list not populating other controls

僤鯓⒐⒋嵵緔 提交于 2019-12-11 06:13:04

问题


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

来源:https://stackoverflow.com/questions/13686232/drop-down-list-not-populating-other-controls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!