我想根据下拉列表从数据库中选择值。我的数据库包含具有字段值的表格:id(primary key),name,fullname,depat
。从下拉列表中选择不符合数据的数据
我的webform1.aspx
页面包含一个下拉列表,Gridview
和SqlDatasource
。
这是我的Webform1.aspx.cs
代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = DropDownList1.SelectedValue.ToString();
SqlConnection con = new SqlConnection(
ConfigurationManager.ConnectionStrings["ztvConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Table1 where name=depat", con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
没有数据从下拉列表中选择值后显示。错误在哪里?
你实际上得到一个错误,或者你只是没有得到预期的效果?是否有将选定值保存为's'的理由?它没有在我看到的其他事件处理程序中使用。 – 2013-03-22 01:05:48