省市县联动dropdownlist
下面就是在提交按钮的单击事件中填写代码(代码区)(前提是把省市县的数据库建好)
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { getddlProvinceDataBind(); //页面首次加载执行省份绑定
} } public void getddlProvinceDataBind() //省份数据绑定 { string sqlProvince = "SELECT * FROM province"; DropDownList2.DataSource = getDataSet(sqlProvince); DropDownList2.DataTextField = "province"; DropDownList2.DataValueField = "provinceID"; DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("--省份--", "0")); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { //第一层,省份选择事件 { int ProvinceID = Convert.ToInt32(DropDownList2.SelectedValue); if (ProvinceID > 0) { string sqlCity = "SELECT * FROM city WHERE father=" + ProvinceID + ""; //根据省份ID找城市 DropDownList3.DataSource = getDataSet(sqlCity); DropDownList3.DataTextField = "city"; DropDownList3.DataValueField = "cityID"; DropDownList3.DataBind();
DropDownList3.Items.Insert(0, new ListItem("--请选择城市--", "0")); } else { DropDownList3.Items.Clear(); DropDownList3.Items.Insert(0, new ListItem("--请选择城市--", "0")); DropDownList3.Items.Clear(); DropDownList3.Items.Insert(0, new ListItem("--请选择县区--", "0")); } } }
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e) { //第二层,城市件 { int CityID = Convert.ToInt32(DropDownList3.SelectedValue); if (CityID > 0) { string sqlDistrict = "SELECT * FROM area WHERE father=" + CityID + ""; //根据城市ID找县区 DropDownList4.DataSource = getDataSet(sqlDistrict); DropDownList4.DataTextField = "area"; DropDownList4.DataValueField = "areaID"; DropDownList4.DataBind();
DropDownList4.Items.Insert(0, new ListItem("--请选择县区--", "0")); } else { DropDownList4.Items.Clear(); DropDownList4.Items.Insert(0, new ListItem("--请选择县区--", "0")); } } }
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e) { int ProvinceID = Convert.ToInt32(DropDownList2.SelectedValue); int CityID = Convert.ToInt32(DropDownList3.SelectedValue); int DistrictID = Convert.ToInt32(DropDownList4.SelectedValue); //if (ProvinceID > 0 && CityID > 0 && DistrictID > 0) //{ // Response.Write("您选择的省份ID:" + ProvinceID + "城市ID:" + CityID + "县区ID:" + DistrictID + ""); //} } public DataSet getDataSet(string sql) //自定义方法,sql语句参数,返回DataSet数据集 { string connection = ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString; SqlConnection conn = new SqlConnection(connection); SqlDataAdapter sda = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); sda.Fill(ds); return ds; }
这样,就完成我们想要的效果了。如下图所示:
省市县联动dropdownlist的更多相关文章
- C#winform省市县联动,以及有的县是空值时显示异常的处理
一.如下comboBox1.comboBox2.comboBox3,原来这三个都是空的, 将数据库中的省份传递到comboBox1中 我的数据库有parent字段,根据市的parent找到省,根据县的 ...
- ajax实现无刷新两级联动DropDownList
ajax实现的无刷新三级联动 http://zhangyu028.cnblogs.com/articles/310568.html 本文来自小山blog:http://singlepine.cnblo ...
- 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏
在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...
- 三级联动---DropDownList控件
AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...
- JavaScript 全国级省市县联动
<div class="right_content clearfix"> <h3 class="common_title2">收货地址& ...
- ASP.NET MVC页面UI之联动下拉选择控件(省、市、县联动选择)
地区选择操作在WEB应用中比较常见的操作,本文在.net mvc3下实现了省市县三级联动选择功能. 本文博客出处:http://www.kwstu.com/ArticleView/admin_2013 ...
- 微信小程序之地址联动
这就是我们要实现的效果 <view class="consignee"> <!-- consignee 收件人 --> <text>收件人: & ...
- 微信小程序---自定义三级联动
在开发的很多电商类型的项目中,免不了会遇到三级联动选择地址信息,如果单纯的使用文本框给用户选择,用户体检可能就会差很多.今天我给大家整理了关于小程序开发利用picker-view组件和animatio ...
- DevExpress控件使用系列--ASPxGridView+Popup+Tab
1.控件功能 列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例 2.1 ASPxGridView http ...
随机推荐
- asp.net core csrf
如果用tag 比如 <form asp-action="Login" asp-controller="Account" method="post ...
- [整理]AngularJS学习资源
https://angular.io/docs/js/latest/(2.0官方网站) http://www.linuxidc.com/Linux/2014-05/102139.htm(Angular ...
- iOS中assign,copy,retain之间的区别以及weak和strong的区别(面试)
• copy: 用于希望保持一份传入值的拷贝,而不是值自身的情况,即把原来的对象完整的赋值到另外一地方,重新加载一内存区,一个地方变了不影响另一个地方的对象. • assign: 简单的直接赋值,相 ...
- Problem B Boxes in a Line
省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...
- Java 7 Concurrency Cookbook 翻译 第一章 线程管理之五
九.使用线程本地变量 一个并发程序的最关键特征就是共享数据.这个特性在那些继承了 Thread 类或者 实现了 Runnable 接口的对象上显得更加重要. 如果你创建一个实现了 Runnable 接 ...
- HNU 12868 Island (简单题)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12868&courseid=272 解题报告:输入n*m ...
- PC-BSD 换名 TrueOS
导读 PC-BSD 重大更新:面向私人电脑的PC-BSD操作系统开发者.Lumina桌面环境创造者Ken Moore今天宣布系统迎来重大改变. 首先,PC-BSD更名为TrueOS,用户依然能够在PC ...
- Unix操作系统中UUCP知识详细讲解
导读 Unix操作系统有很多值得学习的地方,这里我们主要介绍Unix操作系统中的uucp,大家一起来学习下吧!UUCP系统是一组程序,完成文件传输,执行系统之间的命令,维护系统使用情况的统计,保护安全 ...
- 分析Masonry
一. 继承关系 1.MASConstraint (abstract) MASViewContraint MASComposisionConstraint 2. UIView NSLayoutConst ...
- MVPHelper
在MVP的使用过程中,我们需要反复的去写各种MVP的接口和实现类, 实在是 太麻烦了!!所以抽时间撸了一款插件(只可用于Intellj IDEA 和 Android Studio),用于生成MVP接口 ...