选择新项目后刷新 DropdownList 数据
我有两个下拉列表,一个是州,一个是城市。选择州/省/自治区/直辖市后,城市下拉列表将被填充。此时,您可以选择一个城市,但是如果您选择一个城市并返回并选择不同的州,则城市下拉列表将由两个州的城市填充。如何明确第一个州的城市?
这是后面的代码
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Public Sub ddlState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
SqlDataSource2.SelectParameters.Clear()
SqlDataSource2.SelectParameters.Add(New Parameter("@State", DbType.String, ddlState.SelectedValue))
ddlCity.DataBind()
'SqlDataSource2.SelectParameters.Clear()
'Dim State As String = ddlState.SelectedItem.Text
End Sub
Protected Sub ddlCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCity.SelectedIndexChanged
'Dim City As String = ddlCity.SelectedItem.Text
End Sub
I have two dropdownlist, one is State and one is City. When a State is selected, the City dropdownlist becomes populated. At that point you can select a city, however if you select a city and go back and select a different state, the city dropdownlist is populated by the cities for both states. How do I get it clear the cities for the first state?
Here is the code behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Public Sub ddlState_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
SqlDataSource2.SelectParameters.Clear()
SqlDataSource2.SelectParameters.Add(New Parameter("@State", DbType.String, ddlState.SelectedValue))
ddlCity.DataBind()
'SqlDataSource2.SelectParameters.Clear()
'Dim State As String = ddlState.SelectedItem.Text
End Sub
Protected Sub ddlCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCity.SelectedIndexChanged
'Dim City As String = ddlCity.SelectedItem.Text
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以在控件中设置
AppendDataboundItems = 'false'
。You could also set
AppendDataboundItems = 'false'
in the control.