0

早上好。I have a dropdown list control which when a particular item is selected, another dropdown's list is populated based on that selection. 后面的代码如下。

Imports System.IO
Partial Class Data
Inherits System.Web.UI.Page
Private Property _futureslist As List(Of String)
Property FuturesList As List(Of String)
    Get
        Return _futureslist
    End Get
    Set(value As List(Of String))
        Dim strText As String =    File.ReadAllText(HttpContext.Current.Server.MapPath("~/DataFiles/AvailableFutures.txt"))
        Dim arytext() As String = strText.Split(",")
        For i As Integer = 0 To arytext.Count - 1
            value.Add(arytext(i))
        Next
        _futureslist = value
    End Set

End Property
Protected Sub ddlMain_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlMain.SelectedIndexChanged
    If Not IsPostBack Then

        If ddlMain.SelectedItem.Text = "Futures" Then
            ddlMainsub1.DataSource = _futureslist
            ddlMainsub1.DataBind()

        End If
    End If
End Sub
End Class

它为创建列表属性而读取的文件格式如下;玉米、小麦、咖啡

因此,当主下拉选择项是“Futures”时,第二个下拉值将数据绑定到 FuturesList 属性。任何帮助,将不胜感激

4

1 回答 1

1

一组AutoPostBack=True“ddlMain”,然后在

Protected Sub ddlMain_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles ddlMain.SelectedIndexChanged
 ddlMainsub1.Items.Clear()
 'bound items here to DropDownList2
End Sub  

希望能帮助到你。祝你好运。

于 2012-05-17T09:33:09.913 回答