三级联动

数据库根据父级代号条件写查询 返回list<>集合

方法一:

创建三个下拉列表:

※AutoPostBack:否发生自动回传到服务器的操作。如果把该属性设置为 TRUE,则启用自动回传,否则为 FALSE。默认是 FALSE。

 省:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
市:<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"></asp:DropDownList>
区:<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True"></asp:DropDownList>

CS:

※SelectedIndexChanged事件:当列表控件的选定项在信息发往服务器之间变化时发生

     protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind(new ChinaStatesDA().Select(""), DropDownList1);
Bind(new ChinaStatesDA().Select(DropDownList1.SelectedValue), DropDownList2);
Bind(new ChinaStatesDA().Select(DropDownList2.SelectedValue), DropDownList3);
}
DropDownList1.SelectedIndexChanged += DropDownList1_SelectedIndexChanged;
DropDownList2.SelectedIndexChanged += DropDownList2_SelectedIndexChanged;
} void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Bind(new ChinaStatesDA().Select(DropDownList2.SelectedValue), DropDownList3);
} void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Bind(new ChinaStatesDA().Select(DropDownList1.SelectedValue), DropDownList2);
Bind(new ChinaStatesDA().Select(DropDownList2.SelectedValue), DropDownList3);
}
//绑定方法
public void Bind(List<ChinaStates> list, DropDownList dw)
{
dw.DataSource = list;
dw.DataTextField = "AreaName";
dw.DataValueField = "AreaCode";
dw.DataBind();
}

方法二:

创建三个下拉列表框:

 省:<asp:DropDownList ID="DropDownListsheng" runat="server" OnSelectedIndexChanged="DropDownListsheng_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
市:<asp:DropDownList ID="DropDownListshi" runat="server" OnSelectedIndexChanged="DropDownListshi_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
区:<asp:DropDownList ID="DropDownListqu" runat="server" AutoPostBack="True"></asp:DropDownList>

CS:

※DropDownList.Items.Clear(); 每调用一次填充方法就需要请空一下,否则数据会追加

    protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sheng();
shi();
qu();
}
}
public void sheng()//填充省
{
List<ChinaStates> listsheng = new ChinaStatesDA().Select("");
foreach (ChinaStates cssheng in listsheng)
{
ListItem lisheng = new ListItem(cssheng.AreaName, cssheng.AreaCode);
DropDownListsheng.Items.Add(lisheng);
}
}
public void shi()//填充市
{ List<ChinaStates> listshi = new ChinaStatesDA().Select(DropDownListsheng.SelectedValue);
foreach (ChinaStates csshi in listshi)
{
ListItem lishi = new ListItem(csshi.AreaName, csshi.AreaCode);
DropDownListshi.Items.Add(lishi);
}
}
public void qu()//填充区
{ List<ChinaStates> listqu = new ChinaStatesDA().Select(DropDownListshi.SelectedValue);
foreach (ChinaStates csqu in listqu)
{
ListItem liqu = new ListItem(csqu.AreaName, csqu.AreaCode);
DropDownListqu.Items.Add(liqu);
} }
protected void DropDownListsheng_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListshi.Items.Clear();
DropDownListqu.Items.Clear();
shi();
qu();
}
protected void DropDownListshi_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListqu.Items.Clear();
qu();
}

WebForm 三级联动的更多相关文章

  1. Webform 三级联动例子

    首先分别做三个下拉列表 <body> <form id="form1" runat="server"> <asp:DropDown ...

  2. Webform——中国省市三级联动以及IsPostBack

    首先要明白Webform的运行顺序,当开始启动时候,首先执行的是Page_Load事件, 当点击任意按钮后,每次点击都要先执行一遍Page_Load(在这里Page_Load里面的事件是给数据控件加载 ...

  3. webform的三级联动

    webform的三级联动 与winform一样,只不过需把DropDownList的AutoPostBack属性改为True. *简单日期的编写方法:用是三个DropDownList分别代表年月日,用 ...

  4. webForm(三)——三级联动

    三级联动 首先附图一张,初步认识一下什么是三级联动:                           注:选第一个后面两个变,选第二个,最后一个改变. 其次,做三级联动需要注意的方面:①DropD ...

  5. 注册页面的验证 WEB的三级联动

    1.js中window.onload = function () {};表示当页面都加载完了之后才走里面的内容. 2.当函数中遇到return时,会跳出函数,return后面的内容不再继续进行,就是后 ...

  6. js封装的三级联动菜单(使用时只需要一行js代码)

    前言 在实际的项目开发中,我们经常需要三级联动,比如省市区的选择,商品的三级分类的选择等等. 而网上却找不到一个代码完整.功能强大.使用简单的三级联动菜单,大都只是简单的讲了一下实现思路. 下面就给大 ...

  7. 利用select实现年月日三级联动的日期选择效果

    × 目录 [1]演示 [2]规划 [3]结构生成[4]算法处理 前面的话 关于select控件,可能年月日三级联动的日期选择效果是最常见的应用了.本文是选择框脚本的实践,下面将对日期选择效果进行详细介 ...

  8. jQuery省市区三级联动插件

    体验效果:http://hovertree.com/texiao/bootstrap/4/支持PC和手机移动端. 手机扫描二维码体验效果: 代码如下: <!DOCTYPE html> &l ...

  9. jQuery - 全国省市县三级联动

    最近有空用jquery做了一个全国省市县的三级联动,在以后或许可以用的到 ,遗憾的是我还没用封装,等有空看能不能封装成一个插件 废话不多说,贴上代码: <!doctype html> &l ...

随机推荐

  1. CSS-学习笔记六

    1. 自适应,响应式布局 2. pure 3. Animate

  2. nginx 生成 缩略图 and 生成缩略图到硬盘

    nginx  编译的时候增加  ./configure --with-http_image_filter_module 配置如下 server { listen     80; server_name ...

  3. iOS推送的众多坑

    新来的一家公司,昨天和同事解决推送问题(工程里有集成百度推送和环信即时通讯),信誓旦旦的声称:" app在前台和后台运行时,推送触发的是didReceiveRemoteNotificatio ...

  4. heritrix1.14.4配置-没有add和change按钮的问题

    今天搞了下heritrix1.14.4在eclipse下的配置,根据http://www.360doc.com/content/10/0913/18/2793979_53385587.shtml教程, ...

  5. Eclipse perl的IDE环境插件-EPIC

    前提:1.安装好perl环境:ActivePerl(验证方法:cmd中输入 perl -v 看是否有反应~) 2.安装Eclipse 3.0以上版本 可选:安装PadWalker包,主要是全局变量跟踪 ...

  6. 19、手把手教你Extjs5(十九)模块Grid的其他功能的设想

    经过对自定义模块和Grid的设计和编码,现在已经能对一个有配置信息的模块来生成界面并进行一些简单的CURD操作.由于这是一个全解释性的前台的架构,因此你想到的任何新主意都可以放到所有的模块中. 比如对 ...

  7. Instruments使用实战

    http://www.cocoachina.com/ios/20150225/11163.html 最近采用Instruments 来分析整个应用程序的性能.发现很多有意思的点,以及性能优化和一些分析 ...

  8. stm32实现待机唤醒

    STM32的低功耗模式有3种:1.睡眠模式(CM3内核停止,外设仍然运行)2.停机模式(所有时钟都停止)3.待机模式(1.8v内核电源关闭) 进入待机模式的方法,以及设置WK_UP引脚用于把STM32 ...

  9. 可持久化Trie树初步

    可持久化Trie树和可持久化线段树很像,依次插入信息,通过减法来进行历史版本查询. 2015年11月27日 bzoj3261 最大异或和 我们需要计算 a[p] xor a[p+1] xor ... ...

  10. .net面试题【持续更新.....】

    1.C#中readonly和const的区别? 2.C#中的排序继承自哪个接口?Icompare 3.阐述单点登录的实现原理? 4.C#中property和Attribute的区别? 5.Datase ...