zoukankan      html  css  js  c++  java
  • Webfrom --中国直辖市三区联动

    效果图:

    (一)数据库操作方法:
    
    public class mydb
    {
        private MyDBDataContext context = new MyDBDataContext();
        public List<ChinaStates> Select(string AreaCode)//将中国的表全部查询
        {
            return  context.ChinaStates.Where(p=>p.ParentAreaCode==AreaCode).ToList();
        }
    
    }
    (二) 操作方法
    public partial class yemian : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)//显示界面
        {
            if (!IsPostBack)
            {
                fangfa();
            }
    
      
        }
    
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)//根据第一个来操作第二个和第三个
        {
            string code = DropDownList1.SelectedItem.Value;
            List<ChinaStates> diqu1 = new mydb().Select(code);
            DropDownList2.DataSource = diqu1;
            DropDownList2.DataTextField = "AreaName";
            DropDownList2.DataValueField = "AreaCode";
            DropDownList2.DataBind();
    
            List<ChinaStates> diqu3= new mydb().Select(code);
            DropDownList3.DataSource = diqu3;
            DropDownList3.DataTextField = "AreaName";
            DropDownList3.DataValueField = "AreaCode";
            DropDownList3.DataBind();
    
        }
        private void fangfa()//写了一个方法
        {
            List<ChinaStates> list = new mydb().Select("0001");
            DropDownList1.DataSource = list;//制定数据源
            DropDownList1.DataTextField = "AreaName";
            DropDownList1.DataValueField = "AreaCode";
            DropDownList1.DataBind();//最后绑定一下
    
            List<ChinaStates> shi = new mydb().Select("11");
            DropDownList2.DataSource = shi;
            DropDownList2.DataTextField = "AreaName";
            DropDownList2.DataValueField = "AreaCode";
            DropDownList2.DataBind();
    
            List<ChinaStates> diqu = new mydb().Select("1101");
            DropDownList3.DataSource = diqu;
            DropDownList3.DataTextField = "AreaName";
            DropDownList3.DataValueField = "AreaCode";
            DropDownList3.DataBind();
        
        
        }
    
      protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)//根据第二个改变第三个
        {
            string code = DropDownList2.SelectedItem.Value;
            List<ChinaStates> diqu2 = new mydb().Select(code);
            DropDownList3.DataSource = diqu2;
            DropDownList3.DataTextField = "AreaName";
            DropDownList3.DataValueField = "AreaCode";
            DropDownList3.DataBind();
    
        }
    }


    点击改变事件一定要将AutoPostBack 的属性改成true
  • 相关阅读:
    使用CAShapeLayer做出圆形的进度条 —— #DF!
    NSDate分类,把系统返回的时间与现在进行比较---秀清
    NSPredicate类,指定过滤器的条件---董鑫
    UITextFIeld的输入格式问题 ----W.P
    AttributeText创建多彩文字Label --- hl
    自定义简单动画
    Swift 学习网址精选 By HL
    【C++服务端技术】移动广播
    【C++服务端技术】定时器
    【面试攻略】C++面试-4399
  • 原文地址:https://www.cnblogs.com/w-wz/p/4658552.html
Copyright © 2011-2022 走看看