c# webbrowser 实现网页三级联动下拉选择的问题

2024-12-18 21:59:04
推荐回答(3个)
回答1:

参考:
private void bind(){

SqlConnection conn = db.createConn();
string sqlRent = "select * from Rental";
conn.Open();
SqlCommand cmdRent = new SqlCommand(sqlRent, conn);
SqlDataReader sdrRent=cmdRent.ExecuteReader();
ddl_renting.DataSource = sdrRent;
ddl_renting.DataTextField = "rentalName";
ddl_renting.DataValueField = "rentalId";
ddl_renting.DataBind();
sdrRent.Close();
string sqlCity = "select * from Provience";
SqlCommand cmdCity=new SqlCommand(sqlCity,conn);
SqlDataReader sdrCity = cmdCity.ExecuteReader();
ddl_city.DataSource = sdrCity;
ddl_city.DataTextField = "provienceName";
ddl_city.DataValueField = "provienceId";
ddl_city.DataBind();
sdrCity.Close();
string sqlQuyu = "select * from City where c_id="+ddl_city.SelectedValue;
SqlCommand cmdQuyu = new SqlCommand(sqlQuyu,conn);
SqlDataReader sdrQuyu = cmdQuyu.ExecuteReader();
ddl_quyu.DataSource = sdrQuyu;
ddl_quyu.DataTextField = "cityName";
ddl_quyu.DataValueField = "cityId";
ddl_quyu.DataBind();
sdrQuyu.Close();
string sqlCom = "select * from Community where com_id="+ddl_quyu.SelectedValue;
SqlCommand cmdCom = new SqlCommand(sqlCom,conn);
SqlDataReader sdrCom = cmdCom.ExecuteReader();
ddl_xiaoqu.DataSource = sdrCom;
ddl_xiaoqu.DataTextField = "communityName";
ddl_xiaoqu.DataValueField = "communityId";
ddl_xiaoqu.DataBind();
sdrCom.Close();
conn.Close();
}

protected void ddl_city_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn=db.createConn();
string c_id = ddl_city.SelectedValue;
string sql = "select * from City where c_id="+c_id;
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader sdr = cmd.ExecuteReader();
ddl_quyu.DataSource = sdr;
ddl_quyu.DataTextField = "cityName";
ddl_quyu.DataValueField = "cityId";
ddl_quyu.DataBind();
sdr.Close();
conn.Close();
}
protected void ddl_quyu_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = db.createConn();
string c_id = ddl_quyu.SelectedValue;
string sql = "select * from Community where com_id="+c_id;
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader sdr = cmd.ExecuteReader();
ddl_xiaoqu.DataSource = sdr;
ddl_xiaoqu.DataTextField = "communityName";
ddl_xiaoqu.DataValueField = "communityId";
ddl_xiaoqu.DataBind();
sdr.Close();
conn.Close();
}

回答2:

1。通过ID得到省份的元素,赋值为“兰州市”并调用其onchange事件;
2. 通过timer触发5秒后再找到兰州市的value,赋值并调用其onchange事件;
3.通过timer触发5秒后再找到城关区的value,赋值并调用其onchange事件;

如果还不会的话,发你的URL地址出来,我贴代码给你

回答3:

首先你要有全国地区的省市区的列表.选择了省之后根据省筛选出市的列表,然后通过某方式(推荐JQuery)赋值给市的下拉框列表,选完市之后同样的筛选赋值给区.
你可以找一下联动操作的代码看一下.