• DropDownList无刷新及联的简单做法


    一个简单的无刷新DropDownList及联 写个小例子 把DropDownList放入UpdatePanel 中

        //省份数据的列表

        string[][] Provins;

        //城市数据的列表

        string[][] Citys;

        protected void Page_Load(object sender, EventArgs e)
        {
            //手动设置省份列表的内容
           Provins = new string[][]
           {
           new string[]{"1","四川"},
           new string[]{"3","湖北"},
           new string[]{"2","湖南"}
         
           };
            //手动设置城市列表的内容
           Citys = new string[][]
           {
           new string[]{"成都","1"},
           new string[]{"绵阳","1"},
           new string[]{"德阳","1"},
           new string[]{"长沙","2"},
           new string[]{"湘潭","2"},
           new string[]{"武汉","3"},
           new string[]{"荆州","3"},
           };
            if (!IsPostBack)
            {
                //循环给省份下拉列表赋值
                for (int i = 0; i < Provins.Length; i++)
                {
                    string v = Provins[i][1].ToString();
                    DropDownList1.Items.Add(new ListItem(Provins[i][1], Provins[i][0]));
                }
                //循环给城市下拉列表赋值
                for (int i = 0; i < Citys.Length; i++)
                {
                    string c = Citys[i][0].ToString();
                    DropDownList2.Items.Add(new ListItem(Citys[i][0], Citys[i][1]));
                }
            }
        }

       protected void FlushList(object sender, EventArgs e)
        {
            //先清除第二个DropDownList控件中的所有项
            DropDownList2.Items.Clear();
            //循环城市列表
            for (int i = 0; i < Citys.Length; i++)
            {
                string id = Citys[i][1];
                //挑选和省份ID相同的城市添加到第二个DropDownList控件中
                if (DropDownList1.SelectedValue.Equals(Citys[i][1]))
                {
                    string a = DropDownList1.SelectedValue.ToString();
                    DropDownList2.Items.Add(Citys[i][0]);
                }
            }
        }

    以上代码很简单,轻松的就实现无刷新DropDownList及联  比起写一大堆脚本,为了保持状还要态返回参数等等.简单又实用

  • 相关阅读:
    .net Core自定义中间件中读取Request.Body和Response.Body的内容?
    团队项目的Git分支管理规范
    .net core2.2升级3.1
    .net core EF获取SQL
    EF 查询扩展
    IIS Express启动不了的的解决方案
    AutoMapper
    mssql 数据库“查询处理器用尽了内部资源,无法生成查询计划。”问题的处理
    微服务九大特性
    Flink入门
  • 原文地址:https://www.cnblogs.com/feihu/p/1317318.html
Copyright © 2020-2023  润新知