| 
 | 
 
| 归海一刀 | 
 published in(发表于) 2014/1/30 1:27:32 | 
Edit(编辑) | 
 
| 
DropDownList、ListBox实现无刷新三级联动的方法_[Asp.Net教程]
 | 
 
 
 | 
 
| 
DropDownList、ListBox实现无刷新三级联动的方法_[Asp.Net教程]
 | 
 
 
 | 
 
DropDownList、ListBox实现无刷新三级联动的方法_[Asp.Net教程] 前台代码: asp.net实现DropDownList、ListBox无刷新三级联动的两种方法         后台代码:
 
  DB cn = new DB(); 
  Page_Load#region Page_Load  private void Page_Load(object sender, System.EventArgs e)  {  if (!this.IsPostBack)  {  this.down1_bind();  this.ListBox1.Attributes.Add("onchange", "XmlPost2(this);");  this.ListBox2.Attributes.Add("onchange", "XmlPost3(this);");  }  if (povinceid != "")  {  this.down2_bind(povinceid);  }  if (cityid != "")  {  this.down3_bind(cityid);  }  } 
  #endregion 
  property#region property  private string povinceid  {  get  {  if (ViewState["povinceid"] != null && ViewState["povinceid"].ToString() != "")  {  return ViewState["povinceid"].ToString();  }  else  {  if (Request["povinceid"] != null && Request["povinceid"].ToString() != "")  {  return Request["povinceid"];  }  else  {  return "";  }  }  }  set  {  ViewState["povinceid"] = value;  }  }  private string cityid  {  get  {  if (ViewState["cityid"] != null && ViewState["cityid"].ToString() != "")  {  return ViewState["cityid"].ToString();  }  else  {  if (Request["cityid"] != null && Request["cityid"].ToString() != "")  {  return Request["cityid"];  }  else  {  return "";  }  }  }  set  {  ViewState["povinceid"] = value;  }  }  #endregion 
  down2_bind#region down2_bind  private void down2_bind(string id)  {  string mystr = "";  string sql = "select cityID,city from city where father = ’" + id + "’";  DataTable dt = cn.ReturnTable2(sql);  if (dt.Rows.Count != 0)  {  for (int i = 0; i < dt.Rows.Count; i++)  {  mystr += "," + dt.Rows[i][0].ToString() + "|" + dt.Rows[i][1].ToString();  }  mystr = mystr.Substring(1);  }  this.Response.Write(mystr);  this.Response.End();  }  #endregion 
  down3_bind#region down3_bind  private void down3_bind(string id)  {  string mystr = "";  string sql = "select areaID,area from area where father = ’" + id + "’";  DataTable dt = cn.ReturnTable2(sql);  if (dt.Rows.Count != 0)  {  for (int i = 0; i {  mystr += "," + dt.Rows[i][0].ToString() + "|" + dt.Rows[i][1].ToString();  }  mystr = mystr.Substring(1);  }  this.Response.Write(mystr);  this.Response.End();  } 
  #endregion 
  down1_bind#region down1_bind  private void down1_bind()  {  string sql = "select provinceID,province from povince";  DataTable dt = cn.ReturnTable2(sql);  this.ListBox1.DataSource = dt.DefaultView;  this.ListBox1.DataValueField = "provinceID";  this.ListBox1.DataTextField = "province";  this.ListBox1.DataBind();  } 
  #endregion 
 
 
 
 以上是实现listbox的方法,DropDownList的方法与它一样,只要替换下就可以了.  数据库这里上传不了,我把它放到我的资源里,你们要是想要的话,就到我的资源里去下载下来,或者你们自己建表看效果.地址是:http://download.csdn.net/user/ainir1314520;数据库是access的,你们转换下就可以了 
  
 | 
 
| 
 | 
 
 
 
 | 
 |