就如何搞DropdownList去控制数据库,从而数据库的一个表的内容显示在DataList内呢?
protectedvoidDropDownList1_SelectedIndexChanged1(objectsender,EventArgse){Bind();Pane...
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
Bind();
Panel1.Visible = true;
}
private void Bind()
{
string str = DropDownList1.SelectedValue.ToString();
SqlConnection myconn2 = new SqlConnection(ConfigurationManager.AppSettings["constrx2"].ToString());
myconn2.Open();
string sqlstr2 = "select q.* from question q,Course c where q.courseID=c.courseID and c.courseName='" + str + "'";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr2, myconn2);
DataSet myds = new DataSet();
myda.Fill(myds, "table");
DataList1.DataKeyField = "questionID";
// DataList1.DataSource = myds.Tables["table"];
DataList1.DataBind();
myda.Dispose();
myds.Dispose();
myconn2.Close();
} 展开
{
Bind();
Panel1.Visible = true;
}
private void Bind()
{
string str = DropDownList1.SelectedValue.ToString();
SqlConnection myconn2 = new SqlConnection(ConfigurationManager.AppSettings["constrx2"].ToString());
myconn2.Open();
string sqlstr2 = "select q.* from question q,Course c where q.courseID=c.courseID and c.courseName='" + str + "'";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr2, myconn2);
DataSet myds = new DataSet();
myda.Fill(myds, "table");
DataList1.DataKeyField = "questionID";
// DataList1.DataSource = myds.Tables["table"];
DataList1.DataBind();
myda.Dispose();
myds.Dispose();
myconn2.Close();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询