asp.net 中二级联运菜单怎么做
表一
四川
云南
贵州
表二
成都
绵阳
南充
贵阳
六盘水
昆明
大理
丽江
在表一中选择一个省后,在列表框二中只显示该省内的城市,刚接触ASP.NET,大家帮帮忙
------解决方案--------------------http://blog.csdn.net/jxufewbt/archive/2005/12/07/545582.aspx
------解决方案--------------------写个CS,
AJAX也可以using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// provcityservstat 的摘要说明
/// 这个类主要是用来当省/城市/服务站都是下拉进判断,省和城市教师都是autopostback
/// </summary>
public class provcityservstat
{
public DropDownList prov;
public DropDownList city;
public DropDownList servstat;
public string servstat_id;
public provcityservstat()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//绑定省的下拉
public void dataBindToProv()
{
SqlConnection con = db.createSqlConneciton();
con.Open();
SqlCommand cmd = new SqlCommand( "select * from t_prov ", con);
SqlDataReader sdr = cmd.ExecuteReader();
this.prov.DataSource = sdr;
this.prov.DataTextField = "prov_name ";
this.prov.DataValueField = "prov_id ";
this.prov.DataBind();
sdr.Close();
con.Close();
}
//绑定城市下拉
public void dataBindToCity()
{
SqlConnection con = db.createSqlConneciton();
con.Open();
SqlCommand cmd = new SqlCommand( "select * from t_city where city_provid = " + this.prov.SelectedValue, con);
SqlDataReader sdr = cmd.ExecuteReader();
this.city.DataSource = sdr;
this.city.DataTextField = "city_name ";
this.city.DataValueField = "city_id ";
this.city.DataBind();
sdr.Close();
con.Close();
}
//绑定服务站
public void dataBindToServstat()
{
if (this.city.SelectedValue != " ")
{
SqlConnection con = db.createSqlConneciton();
con.Open();
SqlCommand cmd = new SqlCommand( "select * from t_servstat where servstat_cityid = " + this.city.SelectedValue, con);
SqlDataReader sdr = cmd.ExecuteReader();
this.servstat.DataSource = sdr;
this.servstat.DataTextField = "servstat_name ";
this.servstat.DataValueField = "servstat_id ";
this.servstat.DataBind();
sdr.Close();
con.Close();
}
else
{
this.servstat.Items.Clear();
}
}
//一般用于新增时省,城市,服务站的下拉
public void dataBindAdd()
{
dataBindToProv();
dataBindToCity();
dataBindToServstat();
}
//当省的下拉发生变化时
public void databinddropdownprov()
{
dataBindToCity();
dataBindToServstat();
}
//下面开始是用于修改的,根据已知的servstat_id得出是哪个服务站,哪个城市,哪个省
public void dataBindMod()
{
SqlConnection con = db.createSqlConneciton();
con.Open();
SqlCommand cmd = new SqlCommand( "select * from t_servstat,t_city,t_prov where prov_id = city_provid and city_id = servstat_cityid and servstat_id = " + servstat_id, con);