两个DropDownList的联动-----ASP.NET
来源:互联网 发布:js new date 少一天 编辑:程序博客网 时间:2024/05/30 05:42
当第一个DropDownList中的数据变动时,触发 事件onselectedindexchanged,在这个事件中完成对第二个DropDownList的数据绑定;
示例:城市和省份的联动
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BingdingDDLProvince(); BingdingDDLCity(); } } //省份变动事件 protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e) { string id = this.ddlProvince.SelectedValue; string sql = "select * from 城市表 where 所在省份=" + id; Response.Write(sql); this.ddlCity.DataSource = GetDataTable(sql); this.ddlCity.DataTextField = "城市名"; this.ddlCity.DataBind(); } //得到数据表。连接数据库 public static DataTable GetDataTable(string sql) { SqlConnection conn = new SqlConnection("server=.;database=wuliu;uid=sa;pwd=ddx"); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); DataTable dt = new DataTable(); dt.Load(dr);dr放置到dt数据表中 dr.Close(); return dt; } //绑定省份 protected void BingdingDDLProvince() { string sql = "select * from 省份"; this.ddlProvince.DataSource = GetDataTable(sql); this.ddlProvince.DataTextField = "省份名"; DropDownList的数据区域 this.ddlProvince.DataValueField = "省份编号"; DropDownList的对应值 this.ddlProvince.DataBind(); } //绑定城市 protected void BingdingDDLCity() { string sql = "select 城市名 from 城市表 where 所在省份='" + this.ddlProvince.SelectedValue + "'"; this.ddlCity.DataSource = GetDataTable(sql); this.ddlCity.DataTextField = "城市名"; this.ddlCity.DataBind(); }
- 两个DropDownList的联动-----ASP.NET
- ASP.NET 两个DropDownList控件的动态联动
- ASP.NET实现无刷新的DropdownList联动效果(20041204)
- Asp.net—DropDownList与listbox的联动
- ASP.net DropDownList 无刷新联动!
- ASP.net DropDownList 无刷新联动!
- ASP.NET实现无刷新DropDownList联动
- ASP.net DropDownList 无刷新联动菜单
- ASP.net DropDownList 无刷新联动菜单
- ASP.net DropDownList 无刷新联动菜单
- ASP.net DropDownList 无刷新联动
- ASP.net DropDownList 无刷新联动!
- ASP.net DropDownList 无刷新联动!
- ASP.net DropDownList 无刷新联动
- ASP.net DropDownList 无刷新联动菜单
- asp.net实现无刷新DropDownList联动
- asp.net DropDownList 三级联动下拉菜单
- ASP .NET DropDownList多级联动事件
- Hoj 2543 Stone IV
- #ifdef _cplusplus的问题
- java--你可能忽略的细节(二)
- 基于全注解方式的SSH框架
- 第五次课后作业
- 两个DropDownList的联动-----ASP.NET
- 免安装版mysql使用
- ural 1008 Image Encoding
- 浅谈问题解决模型
- ural 1011 Conductors
- Win7系统下利用U盘安装Ubuntu_12.04实现双系统教程
- 深入理解Java内存模型(三)——顺序一致性
- 开归档的数据库,使用append 插入是否该表可以不写日志?
- 2013年微软智在未来暑期实习生招聘部分考题