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 ...
随机推荐
- Javascript类型转换表
各种类型的值 转换为各种类型 String Number Boolean Object undefined "undefined" NaN false 报错 null " ...
- html5标签集结1
1.<bdo>标签:覆盖默认的文本方向. <bdo dir="ltr">Here is some text</bdo> 显示结果(从左到右): ...
- 第三百二十三天 how can I 坚持
人在最绝望的时候会干啥,<进击的巨人>. 可以绝望,但一定要相信还有希望. 今天去看了<美人鱼>,确实挺好吧. 把愤怒归结于无能,其实是大错特错,愤怒是人的情绪的发泄,是人就有 ...
- ubuntu官方源列表网址
http://wiki.ubuntu.org.cn/%E6%BA%90%E5%88%97%E8%A1%A8 (推荐台湾的源)
- MyEclipse 8.6反编译插件安装
一.下载插件文件:jad.exe.jadeclipse http://www.varaneckas.com/sites/default/files/jad/jad158g.win.zip ...
- android Notification和NotificationManager的使用
Notification和NotificationManager 1.Broadcast Receiver组件没有提供可视化的界面来显示广播信息.这里我们可以使用Notification和Notifi ...
- C:指针
指针 指针数组 参考1 参考2 参考3 参考4 1.指针 也是一种变量.指针内部存的是一块内存的地址. //指针: 通常我们说的指针其实是指针变量,相比于其他基本数据类型的变量不同,它存储 ...
- jquery 应用小结
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Hadoop集群基准测试
hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.2.0-tests.jar TestDFSIO -wri ...
- 通过ajax获得json数据后格式的转换
在有些情况下获取到的json数据可能是string类型的,需要把其格式化为json对象才方便解析. a)原生js通过ajax获取到的json 此时返回的数据默认是string型的,所以需要用eval( ...