• 三级联动


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

  • 相关阅读:
    mybatis总结(五)(延迟加载)
    mybatis总结(四)(mybatis的动态sql)
    mybatis总结(三)(resultMap和高级映射-级联)
    mybatis总结(二)(mybatis的基本增删改查实例说明)
    mybatis总结(一)(mybatis的基本定义介绍)
    法门扫地僧简历经验分享
    法门扫地僧面试宝典第五版
    关于https不支持http的解决方案
    浏览器渲染原理
    前端面试宝典第三版
  • 原文地址:https://www.cnblogs.com/mxx0426/p/4352750.html
Copyright © 2020-2023  润新知