下面就是在提交按钮的单击事件中填写代码(代码区)(前提是把省市县的数据库建好)

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的更多相关文章

  1. C#winform省市县联动,以及有的县是空值时显示异常的处理

    一.如下comboBox1.comboBox2.comboBox3,原来这三个都是空的, 将数据库中的省份传递到comboBox1中 我的数据库有parent字段,根据市的parent找到省,根据县的 ...

  2. ajax实现无刷新两级联动DropDownList

    ajax实现的无刷新三级联动 http://zhangyu028.cnblogs.com/articles/310568.html 本文来自小山blog:http://singlepine.cnblo ...

  3. 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏

    在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...

  4. 三级联动---DropDownList控件

    AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...

  5. JavaScript 全国级省市县联动

    <div class="right_content clearfix"> <h3 class="common_title2">收货地址& ...

  6. ASP.NET MVC页面UI之联动下拉选择控件(省、市、县联动选择)

    地区选择操作在WEB应用中比较常见的操作,本文在.net mvc3下实现了省市县三级联动选择功能. 本文博客出处:http://www.kwstu.com/ArticleView/admin_2013 ...

  7. 微信小程序之地址联动

    这就是我们要实现的效果 <view class="consignee"> <!-- consignee 收件人 --> <text>收件人: & ...

  8. 微信小程序---自定义三级联动

    在开发的很多电商类型的项目中,免不了会遇到三级联动选择地址信息,如果单纯的使用文本框给用户选择,用户体检可能就会差很多.今天我给大家整理了关于小程序开发利用picker-view组件和animatio ...

  9. DevExpress控件使用系列--ASPxGridView+Popup+Tab

      1.控件功能     列表控件展示数据.弹框控件执行编辑操作.Tab控件实现多标签编辑操官方说明 2.官方示例       2.1 ASPxGridView                http ...

随机推荐

  1. vim关于 引号和 括号的 高效操作-很好很强大的!

    http://blog.csdn.net/bigshady/article/details/6019963 对括号匹配, 进行跳转, 使用的是%. 匹配的括号, 都会被高亮显示, 但是: 根据光标的 ...

  2. STL删除元素

    1.从vector中删除多个元素: #include <iostream> #include <vector> int main() { std::vector<int& ...

  3. JAVA常用时间操作类

    http://www.360doc.com/content/10/1210/17/2703996_76839640.shtml    在程序里面要获取当前的开始时间和结束时间,以及当前天所在的周的开始 ...

  4. [设计模式] javascript 之 组合模式

    组合模式说明 组合模式用于简单化,一致化对单组件和复合组件的使用:其实它就是一棵树: 这棵树有且只有一个根,访问入口,如果它不是一棵空树,那么由一个或几个树枝节点以及子叶节点组成,每个树枝节点还包含自 ...

  5. Junit初级编码(二)探索JUnit核心

    序,Junit测试是单元测试的一个框架,提供了很多方法,供我们快速开展单元测试.现在就让我们慢慢学习Junit单元测试框架 一.Junit的三个核心概念测试类.测试集.测试运行器 1 测试类 公共的, ...

  6. SQL Server2005主从复制实现

    转自:http://blog.csdn.net/gaojier1000/article/details/5805814 一.     准备工作:1 .在发布服务器上建立一个共享目录,作为发布快照文件的 ...

  7. 关于Html编码问题,例如字符:&#183;

    我写的WCF服务突然报错了... 然后我发现传过来的字符不完整 {"完整":"尼古拉·奥斯特洛夫斯基的信息"} 然后传过来的是:{"完整": ...

  8. POJ 2486 Apple Tree

    好抽象的树形DP......... Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6411 Accepte ...

  9. 在lua脚本中使用我们自定义的精灵类

    首先创建cocos2dx-lua项目,然后在项目中添加我们的自定义精灵类:这里Himi类名为:HSprite // // HSprite.h // cocos2dx_lua_tests_by_Himi ...

  10. windows server 2003下安装iis6+php

    参照http://www.myhack58.com/Article/sort099/sort0100/2012/35579.htm 这篇文章,即可! 前 面我写了<windows安装PHP5.4 ...