private void drpProvinceBind()
{
con = new SqlConnection(connstr);
con.Open();
com = new SqlCommand("select * from Province", con);
read = com.ExecuteReader();
DropDownList3.DataSource = read;
DropDownList3.DataValueField = "ID";
DropDownList3.DataTextField = "Province";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, "--请选择省份--");
DropDownList4.Items.Insert(0, "--请选择城市--");
con.Close();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
con = new SqlConnection(connstr);
con.Open();
com = new SqlCommand("select * from city where provid='" + DropDownList3.SelectedItem.Value + "'", con);
read = com.ExecuteReader();
DropDownList4.DataSource = read;
DropDownList4.DataTextField = "city";
DropDownList4.DataValueField = "Provid";
DropDownList4.DataBind();
con.Close();
}
我现在要取出值,可取出的是对应的ID,我要怎么做?谢谢
{
con = new SqlConnection(connstr);
con.Open();
com = new SqlCommand("select * from Province", con);
read = com.ExecuteReader();
DropDownList3.DataSource = read;
DropDownList3.DataValueField = "ID";
DropDownList3.DataTextField = "Province";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, "--请选择省份--");
DropDownList4.Items.Insert(0, "--请选择城市--");
con.Close();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
con = new SqlConnection(connstr);
con.Open();
com = new SqlCommand("select * from city where provid='" + DropDownList3.SelectedItem.Value + "'", con);
read = com.ExecuteReader();
DropDownList4.DataSource = read;
DropDownList4.DataTextField = "city";
DropDownList4.DataValueField = "Provid";
DropDownList4.DataBind();
con.Close();
}
我现在要取出值,可取出的是对应的ID,我要怎么做?谢谢
解决方案 »
- 想开发mvc程序,vs用什么版本好?个人用的。vs2008,vs2010,2.0,3.5,4.0,Premium,ultimate,teamFoundation
- 关于SqlConnection连接,关闭的问题
- 导出xml时,xsi:noNamespaceSchemaLocation显示不完整?
- 突发奇想,可以设置一个BUTTON定时自动启动吗?
- 用Controls.add动态添加的控件如何保持ViewState?
- 请问 radcombobox 如何联动
- 如何用javascript在客户端访问DataGrid中的CheckBox的值,和绑定列的值啊-急,在线等
- 请问如何动态的创建控件
- ASP.NET与ASP的区别与学习方法与支持环境?
- 菜鸟求助,在线等,散分
- 高手进,,,ASP.NET ,Application和session对象问题!!!!!!!!!!!!!
- Repeater控件发布Atom问题,需要马上知道问题所在
DropDownList3.SelectedItem.Text //取文本
DropDownList3.SelectedItem.Text //取文本
楼上正确
com = new SqlCommand("select * from city where provid='" + DropDownList3.SelectedItem.Value + "'", con);
关联的是provid啊,怎么要值了况且楼主用sqldatareader,怎么没关闭那
只关闭connection
这句有问题
很明显你绑的是ID当然取出的是对应的ID改正方法:DropDownList3.DataValueField = "Province"; DropDownList3.DataTextField = "Province";
DropDownList3.SelectedItem.Text //取文本