,文本框中也没有显示任何内容
中执行您的代码
我一直在尝试运行SQL查询,如果用户从下拉列表中选择项目并将SQL结果放入文本框中。
下拉菜单显示移动模型名称。单击模型应检索和在文本框中显示。
我已经设置了下拉列表以从表"产品"
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select Price from Products WHERE Model='" +DropDownList1.SelectedIndexChanged+ "'", con);
da.Fill(dt);
TextBox1.Text = dt.Rows[0]["Price"].ToString();
,但是即使我单击下拉菜单
如果您使用的是ASP.NET,则必须将下拉列表的AutoPostback设置为true。然后在dropdownlistrongelectedIndexchanged
您的SQL命令无效。应该是
SqlDataAdapter da = new SqlDataAdapter("select Price from Products WHERE
Model='" +DropDownList1.SelectedText+ "'", con);
DropDownList1.SelectedValue
或
DropDownList1.SelectedText
不应该是
DropDownList1.SelectedIndexChanged