asp.net 实现省市级联-----<简单方法1>
2012-06-18 01:20
633 查看
准备工作:数据库自带
1.前台代码部分:
2.后台代码部分:
1.前台代码部分:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" onselectedindexchanged="DropDownList1_SelectedIndexChanged" ontextchanged="DropDownList1_TextChanged" AutoPostBack=true> </asp:DropDownList> <br /> <asp:DropDownList ID="ddl_city" runat="server" onselectedindexchanged="ddl_city_SelectedIndexChanged"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel>
2.后台代码部分:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string sqlstr = "select * from promary"; DataTable dt = sqlhelper.ExcuteDataTable(sqlstr); //1.显示什么数据 DropDownList1.DataTextField = "proName"; DropDownList1.DataValueField = "proId"; DropDownList1.DataSource = dt; DropDownList1.DataBind(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { string proId = DropDownList1.SelectedValue.ToString(); string sqlstr = string.Format("select * from city where proID={0}", proId); DataTable dt = sqlhelper.ExcuteDataTable(sqlstr); ddl_city.DataTextField = "cityName"; ddl_city.DataValueField = "cityId"; ddl_city.DataSource = dt; ddl_city.DataBind(); }
相关文章推荐
- asp.net 实现省市级联-----<简单方法2>----前台实现
- 【C#】对异步请求处理程序IHttpAsyncHandler的理解和分享一个易用性封装 【手记】走近科学之为什么明明实现了IEnumerable<T>的类型却不能调用LINQ扩展方法 【手记】手机网页弹出层后屏蔽底层的滑动响应 【手记】ASP.NET提示“未能创建类型”处理 【Web】一个非常简单的移动web消息框 【手记】解决EXCEL跑SQL遇“查询无法运行或数据库表无法打开...”
- ASP.NET实现公历转农历的简单方法
- [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(5)(IEnumerable<>补充)
- [C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- 【转载】[C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- Asp.net读取AD域信息的方法<转>
- ASP.NET.MVC--注解和反射将Enum转换List<SelectListItem>为@Html.DropDownListFor()下拉列表的通用方法
- Asp.Net使用POST方法最简单的实现
- asp.net简单页面控件赋值实现方法
- ASP.NET中使用 Response.Write("<script>alert('****');</script>");后CSS界面发生变化的解决方法 (经验证)
- ASP.NET页面之间传递值的几种方法<转>
- asp.net页面间传值的几种方法 表单提交 传送页面代码 复制代码 <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server
- asp.net 常用字符串过滤方法 <转>
- Asp.net读取AD域信息的方法<转>
- Asp.Net使用POST方法最简单的实现
- [C#/ASP.NET]List<>中Sort()、Find()、FindAll()、Exist()的使用方法
- asp.net mvc(一) ----------简单封装成通用的List<T>集合
- ASP.NET AJAX异步调用Web Service和页面中的类方法< 收藏>
- <asp.net> 实现返回功能