DropDownList的多级联动的问题最典型的案例就是实现省市级三级联动的案例,对这个问题的描述是当选中山东省之后,在选择市的下拉菜单时,市一栏只出现山东省下面的市。对于县也是同样的道理。

我也做的事情和这个也很相似,只不过我要做的是六级联动,我觉得原理肯定是一样的,只要能做出来三级联动,那按照同样的道理,一定可以做出刘级联动。在网上搜索一番后发现有两种说法,在这里给大家一一阐述。第一:用ajax完成无刷新的方案,第二:使用.netdropdownlist自带的事件SelectedIndexChanged。 对于第一个方法,我是非常想用的,但是要做的东西非常急,新学一门技术时间可能不够(可能是自己懒),对于第二种,网上大多数的会出现不能触发的情况。   两种都是两难的选择,最终,我选择了第二种方式,我觉得不能触发的原因一定是某些设置没有做好。

方法如下:

第一:将页面的ViewState设置为true

第二:将所有的DropDownList的AutoPostBack设置为true

这个时候就可以在每个SelectedIndexChanged函数中编写想要的效果。我的是实现方言名的选择:1.首先选择方言类别(闽南话,官话...等等),2.接下来是这个方言类别的地域(华中,华东,东北.....),3.是这个方言的小片区域如(桂柳,江泽,。。。)4.是城市名,5.是方言的名字,6是省份。

以下我的代码

 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//将大区绑定到DaQu控件
string sqlDaQu = "select distinct BigArea from Reference ";
DropListBind(DropDownListDaQu, TBigArea, sqlDaQu, "BigArea");
DropDownListDaQu.Items.Insert(, new ListItem("大区"));
} }
protected void DropDownListDaQu_SelectedIndexChanged(object sender, EventArgs e) //当选择大区后触发
{
BigArea = DropDownListDaQu.SelectedValue.ToString();
string sqlQu = "select distinct Area from Reference where BigArea='" + BigArea + "' ";
DropListBind(DropDownListQu, TArea, sqlQu, "Area");
DropDownListQu.Items.Insert(, new ListItem("区"));
// Label1.Text = BigArea;
}
protected void DropDownListQu_SelectedIndexChanged(object sender, EventArgs e) //当选择区后触发
{
Area = DropDownListQu.SelectedValue.ToString();
string sqlPian = "select distinct Piece from Reference where BigArea='" + BigArea + "' and Area='" + Area + "'";
DropListBind(DropDownListDaPian, TPiece, sqlPian, "Piece");
DropDownListDaPian.Items.Insert(, new ListItem("片"));
} protected void DropDownListDaPian_SelectedIndexChanged(object sender, EventArgs e)
{
Piece = DropDownListDaPian.SelectedValue.ToString();
string sqlXiaoPian = "select distinct SmallPiece from Reference where BigArea='" + BigArea + "' and Area='" + Area + "' and Piece='" + Piece + "'";
DropListBind(DropDownListXiaoPian, TSmallPiece, sqlXiaoPian, "SmallPiece");
DropDownListXiaoPian.Items.Insert(, new ListItem("小片"));
}
protected void DropDownListXiaoPian_SelectedIndexChanged(object sender, EventArgs e)//当选择片后触发
{
SmallPiece = DropDownListXiaoPian.SelectedValue.ToString();
string sqlDian = "select distinct Point from Reference where BigArea='" + BigArea + "' and Area='" + Area + "' and Piece='" + Piece + "'and SmallPiece='" + SmallPiece + "'";
DropListBind(DropDownListDian, TPoint, sqlDian, "Point");
DropDownListDian.Items.Insert(, new ListItem("点"));
}
protected void DropDownListDian_SelectedIndexChanged(object sender, EventArgs e)//当选择小片后触发
{
Point = DropDownListDian.SelectedValue.ToString();
string sqlProvince = "select distinct State from Reference where BigArea='" + BigArea + "' and Area='" + Area + "' and Piece='" + Piece + "'" +
"and SmallPiece='" + SmallPiece + "' and Point='" + Point + "'";
DropListBind(DropDownListProvince, TState, sqlProvince, "State");
DropDownListProvince.Items.Insert(, new ListItem("省"));
}

这样就完毕了。

DropDownList的多级联动的更多相关文章

  1. 微信小程序-多级联动

    微信小程序中的多级联动 这里用到的案例是城市选择器 先上代码: .wxml <view class="{{boxHide}}"> <view>{{nian} ...

  2. PHP多级联动的学习(一)

    我尝试在ThinkCMF中实现多级联动,首先我开始看了dede的联动类别管理前后台的代码以及他的数据库,经过非常多次的尝试,我渐渐有了一点想法,并给予实施. 首先写出前台的界面.如图. 然后在数据库中 ...

  3. vue在多级联动时,一些情况不用watch而用onchange会更好

    onchange事件在内容改变且失去焦点时触发,因此在一些多级联动需要清空次级内容的时候,用onchange就非常有用了,尤其是浏览器会提前加载数据的情况下.有篇文章可以看一下,链接. PS:路漫漫其 ...

  4. [ PHP+jQuery ] ajax 多级联动菜单的应用:电商网站的用户地址选择功能 ( 二 ) - 仿亚马逊下拉面板

    /** jQuery version: 1.8.3 Author: 小dee Date: 2014.11.8 */ 接上一篇博客. 实现带缓存的仿亚马逊下拉面板 效果图: 图1 初始 图2 点击省份 ...

  5. jQuery cxSelect 多级联动下拉菜单

    随着电商热门,这种多层次的互动更充分地体现在下拉菜单,最明显的是多级联动地址下拉选择,因此,这里是一个简单的分享 jQuery cxSelect 多级联动下拉菜单 cxSelect 它是基于 jQue ...

  6. jQuery插件——多级联动菜单

    jQuery插件——多级联动菜单 引言 开发中,有好多地方用到联动菜单,以前每次遇到联动菜单的时候都去重新写,代码重用率很低,前几天又遇到联动菜单的问题,总结了下,发现可以开发一个联动菜单的功能,以后 ...

  7. JavaScript 多级联动浮动(下拉)菜单 (第二版)

    JavaScript 多级联动浮动(下拉)菜单 (第二版)   上一个版本(第一版请看这里)基本实现了多级联动和浮动菜单的功能,但效果不是太好,使用麻烦还有些bug,实用性不高.这次除了修改已发现的问 ...

  8. MVC实现多级联动

    前言 多级联动(省级联动)的效果,网上现成的都有很多,各种JS实现,Jquery实现等等,今天我们要讲的是在MVC里面,如何更方便.更轻量的实现省级联动呢? 实现效果如下: 具体实现 如图所示,在HT ...

  9. 电商门户网站商品品类多级联动SpringBoot+Thymeleaf实现

    在淘宝.京东等电商网站,其门户网站都有一个商品品类的多级联动,鼠标移动,就显示,因为前端不是我做的,所以不说明前端实现,只介绍后端实现. 搭建部署SpringBoot环境 配置文件配置: 开启了对Th ...

随机推荐

  1. hadoop的simple认证

    目前Hadoop的稳定版本为1.2.1,我们的实验就在hadoop-1.2.1上进行 Hadoop 版本:1.2.1 OS 版本: Centos6.4 环境配置 机器名 Ip地址 功能 用户 Hado ...

  2. 使用Sunny-grok实现内网转发

    Sunny-grok 申请地址:http://www.ngrok.cc ngrok.cfg配置: server_addr: "server.ngrok.cc:4443" auth_ ...

  3. Cocos2d-JS v3.0 alpha不支持cocos2d-x的Physics integration

    cocos2d-x 3.0新的Physics integration,把chipmunk和Box2D封装到引擎内部 auto scene = Scene::createWithPhysics(); s ...

  4. 查看MySql中每个IP的连接数

    要统计数据库的连接数,我们通常情况下是统计总数,没有细分到每个IP上.现在要监控每个IP的连接数,实现方式如下: ) as ip , count(*) from information_schema. ...

  5. USB枚举过程(2)

    用bus hound 得到的数据 GET MAX LUN 命令 详见USB_MSC_BlukOnly_v1.0 接下来用到的是UFI  SCSI

  6. AJAX小练习,防止以后忘记

    <div id="content"> <input id="btnShow" type="button" value=&q ...

  7. 几种连接不同数据库的ADO.NET字符串

    Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;或者 Ser ...

  8. defaultAutoCommit

    driver default The default auto-commit state of connections created by this pool. If not set then th ...

  9. fastcgi 分布式

    以lighttpd fastcgi写一下自己对fastcgi分布式的理解. 假设一台机器A上运行lighttpd,在这台主机上只是对请求进行分发. 而在其他多台机器上运行多个fastcgi进程,用来接 ...

  10. C:基本语句

    基本语句知识 do{}while(); 与 while()do{}:for :while 语句的区别: while()do{}:先判断条件是否成立,条件满足则执行循环体 do{}while();是先执 ...