zoukankan      html  css  js  c++  java
  • 三级联动

    public void getProdata() //第一级
    {
    List<ChinaStates> list = new List<ChinaStates>();

    var query = from r in DataC.ChinaStates where r.ParentAreaCode == "0001" select r;
    list = query.ToList();
    foreach (ChinaStates cdata in list)
    {
    ListItem lt = new ListItem(cdata.AreaName, cdata.AreaCode);
    DropDownList1.Items.Add(lt);
    }

    }


    public void getcitydata(string code) //第二级
    {
    List<ChinaStates> list = new List<ChinaStates>();

    var query = from r in DataC.ChinaStates where r.ParentAreaCode == code select r;
    list = query.ToList();
    DropDownList2.Items.Clear();
    foreach (ChinaStates cdata in list)
    {
    ListItem lt = new ListItem(cdata.AreaName,cdata.AreaCode);
    DropDownList2.Items.Add(lt);
    }

    }

    public void getquxiandata(string code) //第三级
    {
    List<ChinaStates> list = new List<ChinaStates>();
    var query = from r in DataC.ChinaStates where r.ParentAreaCode == code select r;
    list = query.ToList();
    DropDownList3.Items.Clear();
    foreach (ChinaStates cdata in list)
    {
    ListItem lt = new ListItem(cdata.AreaName, cdata.AreaCode);
    DropDownList3.Items.Add(lt);
    }

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
    getcitydata(DropDownList1.SelectedValue);
    UpdatePanel1.Update();
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
    getquxiandata(DropDownList2.SelectedValue);
    UpdatePanel1.Update();
    }


    方法二:

    DataClassesDataContext context = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
    //IsPostBack当前请求是否第一次打开,只有在第一次打开的时候是false,其它时候都是true
    //在每个Load页面写代码之前,都加上这句话
    getProdata();
    getcitydata();
    getquxiandata();
    }
    ///// <summary>
    ///// 三级联动
    ///// </summary>
    public void getProdata()
    {
    var query = context.Members.Where(p => p.ParentId == 0);
    DropDownList1.DataSource = query;
    DropDownList1.DataTextField = "Name";
    DropDownList1.DataValueField = "id";
    DropDownList1.DataBind();
    }
    public void getcitydata()
    {
    string name1 = DropDownList1.SelectedValue;

    var query = context.Members.Where(p => p.ParentId == int.Parse(name1));

    DropDownList2.DataSource = query;
    DropDownList2.DataTextField = "Name";
    DropDownList2.DataValueField = "id";
    DropDownList2.DataBind();
    }

    public void getquxiandata()
    {
    string name2 = DropDownList2.SelectedValue;

    var query = context.Members.Where(p => p.ParentId == int.Parse(name2));

    DropDownList3.DataSource = query;
    DropDownList3.DataTextField = "Name";
    DropDownList3.DataValueField = "id";
    DropDownList3.DataBind();
    }


    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
    getcitydata();
    getquxiandata();
    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
    getquxiandata();
    }

  • 相关阅读:
    Cocos2d-x3.0游戏实例之《别救我》第四篇——乱入的主角
    TRIZ系列-创新原理-21-高速通过原理
    “cvSnakeImage”: 找不到标识符
    21世纪创业与知识之间的辩证关系
    Android导航栏ActionBar的具体分析
    HDU4565 && 2013年长沙邀请赛A题
    从切比雪夫不等式到大数定理
    在线笔试琐碎
    在线笔试琐碎
    算法求解中的变量、数组与数据结构(STL 中的容器)
  • 原文地址:https://www.cnblogs.com/mxx0426/p/4352750.html
Copyright © 2011-2022 走看看