省市县联动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 ...
随机推荐
- 关于linux vi命令替换的使用说明
转自:http://os.51cto.com/art/200907/140987.htm vi/vim 中可以使用 :s 命令来替换字符串.以前只会使用一种格式来全文替换,今天发现该命令有很多种写法( ...
- CF456D A Lot of Games (字典树+DP)
D - A Lot of Games CF#260 Div2 D题 CF#260 Div1 B题 Codeforces Round #260 CF455B D. A Lot of Games time ...
- Hadoop Fsimage 和 editlog
在<Hadoop NameNode元数据相关文件目录解析>文章中提到NameNode的$dfs.namenode.name.dir/current/文件夹的几个文件: 1 current/ ...
- FLAG是什么公司
答: facebook, linkedin, alphabeta,airbnb,amazon,apple, google
- Spark之Streaming
1. socket消息发送 import java.net.ServerSocket import java.io.PrintWriter import scala.collection.mutabl ...
- wp手机 htc x310e
入手htc x310e 手机不错,用着流畅 不习惯,已升到wp7.8,系统限制还是有些需要的功能没有,比如说短信拦截什么的 我需要的常用软件少 转手了 1 注销windows live? 设置--应用 ...
- 迟来的Android的Camera开发总结
这是好久前写的项目,但一直没有去总结.刚好在准备找工作这段时间来总结自己做过的东西,学到的东西. 写Android的自定义的相机应用时,首先要知道一些Camera开发必须知道的尺寸,不然在调试的时候, ...
- UNITY3D在线更新之道-CSlight 使用总结
转自:http://blog.csdn.net/leonwei/article/details/39233775 最近做U3D的热更新,研究了各种方式无果后,最容易最先想到的方式就是利用c#的反射机制 ...
- php中mysql与mysqli的区别
两个函数都是用来处理DB 的.首先, mysqli 连接是永久连接,而mysql是非永久连接. mysql连接每当第二次使用的时候,都会重新打开一个新的进程,而mysqli则只使用同一个进程,这样可以 ...
- 2016年10月16日--ArrayList集合、特殊集合
ArrayList集合 使用前引用 using System.Collections; ArrayList集合 实例化.初始化 ArrayList al = new ArrayList(); Arra ...