如何从另一个dreopdownlist更改事件更改dropdownlist的项目 [英] How to change the item of a dropdownlist from another dreopdownlist change event

查看:116
本文介绍了如何从另一个dreopdownlist更改事件更改dropdownlist的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个下拉列表,一个用于城市(ddlcity),另一个用于位置(ddllocation).我想从城市下拉列表中选择一个城市,然后在位置下拉列表中仅显示该城市位置.
例如:让我们在ddlcity中选择gurgaon城市,然后在ddllocation中仅显示gurgaon中的位置.

谢谢.

Hi,

I have two dropdownlist one is for city (ddlcity) and another is for location (ddllocation). I want when I select a city from city dropdownlist then only that city location should show in location dropdownlist.
for example: lets select gurgaon city in ddlcity then only location in gurgaon should show in ddllocation.

Thank You.

推荐答案

如果城市及其位置的数量不是很多,则可以使用JavaScript(或者更好的jQuery来做到这一点).在Google中搜索级联下拉列表javascript",您将获得成千上万的示例.

另一种方法是从服务器获取详细信息.检查一下- CascadingDropDown [
If the number of cities and their locations are not very much, then you can use JavaScript (or better jQuery to do the same). Search Google for "cascading dropdownlist javascript" and you will get thousands of example.

The other way is to get the details from server. Check this out - CascadingDropDown[^]. The example tells how to use it as well.

Hope this helps!


Protected Sub ddlcity_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim cmd As New SqlCommand("select location  from mstCities where  city = ''" & ddlcity.SelectedItem.Text & "''", con)
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            ddllocation.DataSource = dr
            ddllocation.DataBind()
        End While
        con.Close()
    End Sub

<pre>


这篇关于如何从另一个dreopdownlist更改事件更改dropdownlist的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆