三级联动

数据库根据父级代号条件写查询 返回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. 搭建firefly服务端遇到的问题

    1 pylinter pylinter could not automatically determined the path to "lint.py" 这个错误通过安装pylin ...

  2. SQL Server--导入和导出向导

    作用:创建一个只需要最少的转换就可以快速导入或导出数据的包 操作步骤: 1 打开打入和导出向导方式 有四种方式 1)在SSMS(SQL Server Management Studio)中,右击目标数 ...

  3. 配置 Gitblit 进行 Git 代码管理

    配置 Gitblit 进行 Git 代码管理 环境 CentOS 7 x64 IP: 10.6.0.2 首先需要安装jdk  安装步骤 就略过了 下载最新版本  gitblit wget http:/ ...

  4. 用C语言写一个“事件”的模拟程序

    源:用C语言写一个“事件”的模拟程序 Example.c //定义一个函数指针 func int (*func) (void); //调用该函数相当于触发了事件. //该事件触发后,会检查函数指针fu ...

  5. UISegmentedControl——分段控件

    分段控件,提供了一组按钮,但是只能激活一个.通过UIControlEventValueChanged事件实现与用户的交互,并通过selectedSegmentIndex判断当前选定的控件,通过titl ...

  6. 打包程序时的证书问题(上传APP就出现Missing iOS Distribution signing indetity for)

    现象: 解决办法: 1.删除本地钥匙串中的这个文件,注意“系统”中的同名文件也必须删除 2.进入http://www.apple.com/certificateauthority/ 下载新的(WWDR ...

  7. Memcached源码分析之请求处理(状态机)

    作者:Calix 一)上文 在上一篇线程模型的分析中,我们知道,worker线程和主线程都调用了同一个函数,conn_new进行事件监听,并返回conn结构体对象.最终有事件到达时,调用同一个函数ev ...

  8. TLD视觉跟踪算法(转)

    源:TLD视觉跟踪算法 TLD算法好牛逼一个,这里有个视频,是作者展示算法的效果,http://www.56.com/u83/v_NTk3Mzc1NTI.html.下面这个csdn博客里有人做的相关总 ...

  9. IOS中单例NSUserDefaults的使用(转)

    一.了解NSUserDefaults以及它可以直接存储的类型 http://my.oschina.net/u/1245365/blog/294449 NSUserDefaults是一个单例,在整个程序 ...

  10. 动态添加试题选项按钮 radioButton(一)

    最近在做WebView加载试题的功能,但是选项按钮如果放的WebView中,点击时反应很慢.于是把选项用原生的RadioButton,而试题题目和答案放在WebView中.但是选项的个数不确定,所以需 ...