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
  • 相关阅读:
    为什么一刷新页面session没了
    Dedecmsv5.7整合ueditor 图片上传添加水印
    DedecmsV5.7本地上传缩略图无法自动添加水印的解决方法
    mysql find_in_set()函数的使用
    利用phpqrcode二维码生成类库和imagecopymerge函数制拼接图片的经验
    dedecms自定义表单时间时间戳值类型的转换方法
    jquery 根据自定义属性选择
    jquery快速获得url 的get传值
    自定义Bean初始化和销毁方法
    Spring常用注解
  • 原文地址:https://www.cnblogs.com/w-wz/p/4658552.html
Copyright © 2011-2022 走看看