zoukankan      html  css  js  c++  java
  • DropDownList通过数组方式实现两个DropDownList联动

    拖两个DropDownList控件到aspx设计

    选中第一个控件,在DropDownList任务里面选择编辑项添加三个值,如图:

    在第二个DropDownList添加一项:请选择

    查看源:

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="ddlGD" runat="server" AutoPostBack="true"
                onselectedindexchanged="ddlGD_SelectedIndexChanged">
            <asp:ListItem>请选择</asp:ListItem>
            <asp:ListItem>广东</asp:ListItem>
            <asp:ListItem>四川</asp:ListItem>
            </asp:DropDownList>
            <asp:DropDownList ID="ddlSC" runat="server">
            <asp:ListItem>请选择</asp:ListItem>
            </asp:DropDownList>
        </div>
        </form>
    </body>

    打开后置cs文件:

    public partial class _Default : System.Web.UI.Page
    {
        string[] GdCtiy = new string[2] { "深圳", "广州" };
        string[] ScCtiy = new string[2] { "成都", "达州" };
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ddlGD_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlGD.SelectedValue == "广东")
            {
                ddlSC.DataSource = GdCtiy;
            }
            else if(ddlGD.SelectedValue == "四川")
            {
                ddlSC.DataSource = ScCtiy;
            }
            ddlSC.DataBind();
           
        }
    }

  • 相关阅读:
    亨元模式
    模板方法模式
    组合模式
    命令模式
    Android AIDL使用介绍(2)自定义数据类型的传递*
    Android主线程(ActivityThread)源代码分析
    一个简单的死锁代码*
    ABA问题的本质及其解决办法*
    Java 多线程Atomic 与CAS 原理剖析*
    Java并发编程:volatile关键字解析*
  • 原文地址:https://www.cnblogs.com/scsuns520/p/1632785.html
Copyright © 2011-2022 走看看