• 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();
           
        }
    }

  • 相关阅读:
    将node.js代码放到阿里云上,并启动提供外部接口供其访问
    Linux内核深度解析之内核互斥技术——读写信号量
    man 1 2 3 4...
    Android Sepolicy 相关工具
    selinux misc
    ext4 mount options
    tune2fs cmd(ext fs)
    /dev/tty node
    kernel misc
    fork & vfork
  • 原文地址:https://www.cnblogs.com/scsuns520/p/1632785.html
Copyright © 2020-2023  润新知