【发布时间】:2011-12-26 06:52:59
【问题描述】:
基本上我有一个有 2 个下拉菜单的表单。在第一个下拉列表中,我选择了城市类别。选择城市后,我想根据第一个下拉菜单中选择的第一个值更新第二个下拉值。我做过这样的, 这会在第一个下拉列表中添加值:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim s As String = "connection String"
sqlconn = New SqlConnection(s)
sqlCmd = New SqlCommand("select DISTINCT City from usrRegister_aunthentication", sqlconn)
If sqlconn.State = Data.ConnectionState.Closed Then
sqlconn.Open()
End If
dataReader = sqlCmd.ExecuteReader()
While dataReader.Read
Citydropdown.Items.Add(dataReader("City").ToString())
End While
dataReader.Close()
If sqlconn.State = Data.ConnectionState.Open Then
sqlconn.Close()
End If
End Sub
现在假设我选择了一个城市,它应该更新第二个下拉列表,因为我已经这样做了:
Protected Sub Citydropdown_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Citydropdown.Load
Dim CityID As Integer = Convert.ToInt32(Citydropdown.SelectedValue.ToString())
FillStates(CityID)
End Sub
Private Sub FillStates(ByVal CityID As Integer)
Dim strConn As String = "server=.;database=Opex;integrated security=true;pooling=false;"
Dim con As New SqlConnection(strConn)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "sql statement"
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
If objDs.Tables(0).Rows.Count > 0 Then
'HallsDropDown.DataSource = objDs.Tables(0)
'HallsDropDown.DataTextField = "Theater_Name"
'HallsDropDown.DataBind()
'HallsDropDown.Items.Insert(0, "--Select--")
Else
Response.Write("No states found")
End If
End Sub
End Class
我的 XML 如下。任何人都可以通过从第一个下拉列表中选择索引来帮助我在第二个下拉列表中添加值吗?
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<table style="height:50px;">
<tr>
<td>
<asp:Label Text="Select your City" runat="server" ID="lblcity"></asp:Label>
</td>
<td>
<asp:DropDownList ID="Citydropdown" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:label runat="server" id="lblHals" Text="Select Your Halls" ></asp:label>
</td>
<td>
<asp:DropDownList ID="HallsDropDown" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</html>
【问题讨论】:
-
@AVD 我已经更新了问题你能帮帮我吗
标签: asp.net vb.net drop-down-menu