1

我是 webapps 的完全新手,但这里有。

我有一个带有下拉列表的 Web 表单,该列表从数据库过程中填充度假胜地列表。那一点效果很好。当我从列表中选择一个项目时,我需要用特定于该度假村的酒店填充一个列表框。

这一点我遇到了麻烦,如果我单击下拉列表到表单上的日历控件上,列表会填充。

问题:在我单击下拉列表中的值后,如何让它填充列表?

谢谢

顺便说一下,这里是代码:

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
4

0 回答 0