时间:2021-07-01 10:21:17 帮助过:22人阅读
选中 省 ajax 取得 市 列表
并不需要再修改 省 列表了
怎么选中省呢??
那我就奇怪了,你不是 省市联动 吗?
选中省 当然是用户的事情啦
Ajax实现数据库填充省市下拉框联动菜单示例
//Ajax和DropDownList设置
onselectedindexchanged="dlSheng_SelectedIndexChanged">
//调用数据库显示下拉框数据
SqlConnection sqlcon;
string strCon = ConfigurationManager.AppSettings["conn"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "select tbSheng from tb_Sheng";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds);
dltbSheng.DataSource= myds;
dltbSheng.DataValueField = "tbSheng";
dltbSheng.DataBind();
string strtb_Shi = "select * from dl_Shi where tbSheng='" + dltbSheng.SelectedItem.Text + "'";
SqlDataAdapter mydaShi = new SqlDataAdapter(strtb_Shi, sqlcon);
DataSet mydsShi = new DataSet();
mydaShi.Fill(mydsShi);
ddlShi.DataSource = mydsShi;
ddlShi.DataValueField = "tb_Shi";
ddlShi.DataBind();
sqlcon.Close();
}
}
protected void dlSheng_SelectedIndexChanged(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "select * from dl_Shi where tbSheng='" + dltbSheng.SelectedItem.Text+ "'";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds);
ddlShi.DataSource = myds;
ddlShi.DataValueField = "tb_Shi";
ddlShi.DataBind();
sqlcon.Close();
}