使用下拉列表 [英] Working with dropdownlist

查看:75
本文介绍了使用下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
        <asp:ListItem>--select university--</asp:ListItem>
        <asp:ListItem Value="1">MIT</asp:ListItem>
        <asp:ListItem Value="2">Oxford</asp:ListItem>
        <asp:ListItem Value="3">Melbourne</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
        <asp:ListItem>--select country--</asp:ListItem>
        <asp:ListItem Value="1">USA</asp:ListItem>
        <asp:ListItem Value="2">UK</asp:ListItem>
        <asp:ListItem Value="3">Australia</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True">
        <asp:ListItem>--select continent--</asp:ListItem>
        <asp:ListItem Value="1">America</asp:ListItem>
        <asp:ListItem Value="2">Europe</asp:ListItem>
        <asp:ListItem Value="3">Asia</asp:ListItem>
    </asp:DropDownList>





问题

如何在后端编码,以便在dropdownlist1中选择MIT时,美国和America分别在dropdownlist2和dropdownlist3中自动选择。同样是牛津和墨尔本。



谢谢。



QUESTION
How can I code in the back-end such that when "MIT" is selected in dropdownlist1, "USA" and "America" are automatically selected in dropdownlist2 and dropdownlist3 respectively. likewise to "Oxford" and "Melbourne".

Thank you.

推荐答案

你需要的是什么级联下拉菜单 -

ASP.Net中的级联下拉菜单 [ ^ ]

在选择ASP上填充级联DropDownList .NET [ ^ ]
What you need is a cascading dropdown -
Cascading Dropdown in ASP.Net[^]
Populate Cascading DropDownList On Selection ASP.NET[^]


根据我的假设,如果这些数据是静态数据,那么你可以这样做。





首先为下拉列表1创建一个selected_indexchanged事件。



在那个方法中你可以这样做



As per my assumption if this data is static data then you can do like this way.


first Create an selected_indexchanged event for dropdown list1.

In That method you can do like this

Public void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
    {
if(dropdownlist1.selectedIndex!=0)
{
dropdownlist2.selectedIndex= dropdownlist3.selectedIndex=dropdownlist1.selectedIndex;
}





试一次:)



Try this once :)


这篇关于使用下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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