省市县联动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 ...
随机推荐
- UvaLive6662 The Last Ant 模拟
UvaLive6662 PDF题目 题意:给出隧道长度L,蚂蚁数量N,各蚂蚁位置Pi.前进方向Di,都为整数(前进方向为L或R),蚂蚁速度为1cm每秒,两蚂蚁若在整数点相遇则都反向,若不在整数点相遇则 ...
- BufferedReader readLine()方法
控制台输入字符串之后回车,后台接收传来的字符串,代码如下: import java.io.BufferedReader; import java.io.IOException; import java ...
- grep之字符串搜索算法Boyer-Moore由浅入深(比KMP快3-5倍)
这篇长文历时近两天终于完成了,前两天帮网站翻译一篇文章“为什么GNU grep如此之快?”,里面提及到grep速度快的一个重要原因是使用了Boyer-Moore算法作为字符串搜索算法,兴趣之下就想了解 ...
- 2015年11月26日 Java基础系列(六)正则表达式Regex
package com.demo.regex; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @autho ...
- Web前端开发规范文档(google规范)
(Xee:其实没什么规范约束,但是养成一种好习惯,何乐而不为?) 区分大小写 xhtml 区分大小写,xhtml要求 标签名 属性名 值都要小写,并且要有双引号和 标签闭合. css 元素名称以及i ...
- C#中的抽象方法和虚方法有什么区别?
抽象方法是只有定义.没有实际方法体的函数,它只能在抽象函数中出现,并且在子类中必须重写:虚方法则有自己的函数体,已经提供了函数实现,但是允许在子类中重写或覆盖.重写的子类虚函数就是被覆盖了.
- findByExample(Object exampleEntity)方法得到的List判断是否为空,不可用(lis != null)
用findByExample(Object exampleEntity)方法可以应用在用户登录上面,获得有登陆名和密码的user对象进行查询. 返回两者都符合的对象列表,为空则登陆失败. 错误的方法: ...
- HomeWork2
程序一: 1 public intfindLast(int[] x, inty) { 2 //Effects: If x==null throw NullPointerException 3 // e ...
- Android学习笔记函数
//调用新的Activity Intent intent=new Intent(MainActivity.this,Main2Activity.class); startActivity(intent ...
- 用CSS画个三角形
<!DOCTYPE html> <html> <head> <style type="text/css"> #trangle { d ...