DropDownList实现省级-市级-县-镇;联动
我在其中遇到了无论如何后台获取到的值永远是第一个,我绑定数据的时候加了IsPostBack判断了的,求解。。。...
我在其中遇到了 无论如何后台获取到的值永远是第一个,我绑定数据的时候加了IsPostBack判断了的,求解。。。
展开
3个回答
展开全部
你说的“无论什么时候后台获取到的值永远是第一个”是什么意思?感觉你表意太不明确了,是选择某项后,所选的值还是第一项还是怎么呢?如果是这种情况的话可能就是SelectedIndexChanged事件根本就没触发,这时你就得检查你的DropDownList是否加了AutoPostBack属性了,只有这个属性的值为True才能触发事件,这里和IsPostBack没多大关系的,IsPostBac只是判断是否是回发请求的.....
更多追问追答
追问
都设定了的。。这个没错吧
追答
没错是得这样设定。但你刚才所说的获取到的值永远是第一个,是什么意思呢,你能具体描述下你的问题吗?不然这样我也说不清,我也不知道你的后台代码是怎样写的啊
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态住宅IP的服务商。动态住宅IP可以为用户提供更加灵活和稳定的网络连接,同时也可以用于一些特定的网络应用场景,例如网络游戏、视频直播等。使用StormProxies的动态住宅IP服务,用户可以通过更换IP...
点击进入详情页
本回答由Storm代理提供
展开全部
参考:
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();
}
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();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的取值代码是不是 有点问题呢? ,下面三种取值方法,建议首选第一种
DropDownList1.SelectedItem.Value;
DropDownList1.SelectedValue;
DropDownList1.Items[DropDownList1.SelectedItem].Value;
DropDownList1.SelectedItem.Value;
DropDownList1.SelectedValue;
DropDownList1.Items[DropDownList1.SelectedItem].Value;
追问
不是取值问题,都没发现什么问题,重新新建一个页面代码复制过去就对了。。奇葩。你有没有用DropDownList实现 省 -市-县 绑定数据库三级联动的例子呢,有的话发下邮箱 787348086@qq.com谢谢哈!!
追答
手里面没有,但网上很多啊,你百度下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询