DropDownList的多级联动
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的多级联动的更多相关文章
- 微信小程序-多级联动
微信小程序中的多级联动 这里用到的案例是城市选择器 先上代码: .wxml <view class="{{boxHide}}"> <view>{{nian} ...
- PHP多级联动的学习(一)
我尝试在ThinkCMF中实现多级联动,首先我开始看了dede的联动类别管理前后台的代码以及他的数据库,经过非常多次的尝试,我渐渐有了一点想法,并给予实施. 首先写出前台的界面.如图. 然后在数据库中 ...
- vue在多级联动时,一些情况不用watch而用onchange会更好
onchange事件在内容改变且失去焦点时触发,因此在一些多级联动需要清空次级内容的时候,用onchange就非常有用了,尤其是浏览器会提前加载数据的情况下.有篇文章可以看一下,链接. PS:路漫漫其 ...
- [ PHP+jQuery ] ajax 多级联动菜单的应用:电商网站的用户地址选择功能 ( 二 ) - 仿亚马逊下拉面板
/** jQuery version: 1.8.3 Author: 小dee Date: 2014.11.8 */ 接上一篇博客. 实现带缓存的仿亚马逊下拉面板 效果图: 图1 初始 图2 点击省份 ...
- jQuery cxSelect 多级联动下拉菜单
随着电商热门,这种多层次的互动更充分地体现在下拉菜单,最明显的是多级联动地址下拉选择,因此,这里是一个简单的分享 jQuery cxSelect 多级联动下拉菜单 cxSelect 它是基于 jQue ...
- jQuery插件——多级联动菜单
jQuery插件——多级联动菜单 引言 开发中,有好多地方用到联动菜单,以前每次遇到联动菜单的时候都去重新写,代码重用率很低,前几天又遇到联动菜单的问题,总结了下,发现可以开发一个联动菜单的功能,以后 ...
- JavaScript 多级联动浮动(下拉)菜单 (第二版)
JavaScript 多级联动浮动(下拉)菜单 (第二版) 上一个版本(第一版请看这里)基本实现了多级联动和浮动菜单的功能,但效果不是太好,使用麻烦还有些bug,实用性不高.这次除了修改已发现的问 ...
- MVC实现多级联动
前言 多级联动(省级联动)的效果,网上现成的都有很多,各种JS实现,Jquery实现等等,今天我们要讲的是在MVC里面,如何更方便.更轻量的实现省级联动呢? 实现效果如下: 具体实现 如图所示,在HT ...
- 电商门户网站商品品类多级联动SpringBoot+Thymeleaf实现
在淘宝.京东等电商网站,其门户网站都有一个商品品类的多级联动,鼠标移动,就显示,因为前端不是我做的,所以不说明前端实现,只介绍后端实现. 搭建部署SpringBoot环境 配置文件配置: 开启了对Th ...
随机推荐
- 关于python requests包新版本设置代理的问题
在更新了requests包之后,发现我电脑上的charles工具无法再成功抓取到数据包.百度了半年都没有找到原因. 然后 我使用了 google 查到了 charles的最新的文档发现.需要设置代理, ...
- Java并发编程:Timer和TimerTask
Java并发编程:Timer和TimerTask 下面内容转载自: http://blog.csdn.net/xieyuooo/article/details/8607220 其实就Timer来讲就是 ...
- c/c++,输入一个字符 2014-11-20 07:00 30人阅读 评论(0) 收藏
getch().getche()和getchar()函数 (1) getch()和getche()函数 这两个函数都是从键盘上读入一个字符.其调用格式为: getch(); ...
- Encapsulating Data
[Encapsulating Data] The synthesized methods follow specific naming conventions: The method used to ...
- python 递归遍历文件夹
#!/usr/bin/python import os.path def readXmls(folder): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for ...
- SQL语句查找重复记录
select * from AM_C4_ENTRY t where t.created_by in ( select t.created_by from AM_C4_ENTRY t group by ...
- DNS原理及其解析过程(转)
转自(http://369369.blog.51cto.com/319630/812889) 网络通讯大部分是基于TCP/IP的,而TCP/IP是基于IP地址的,所以计算机在网络上进行通讯时只能识别如 ...
- 队列与DelphiXe新语法
好久没写代码了,更久没上博客园的博客了,无聊写几行试一下新语法. 1 unit Main; interface uses Winapi.Windows, Winapi.Messages, System ...
- C++中回调函数(CallBack)的使用
如果试图直接使用C++的成员函数作为回调函数将发生错误,甚至编译就不能通过. 其错误是普通的C++成员函数都隐含了一个传递函数作为参数,亦即“this”指针,C++通过传递this指针给其成员函数从而 ...
- Uncaught TypeError: Object #<Object> has no method 'fancybox'
Uncaught TypeError: Object #<Object> has no method 'fancybox' 2011-10-24 16:51:19| 分类: html|举 ...