创建了一个下拉列表。我的数据库表包含 2 个表
Studentregtable : ID int,FullName varchar,UserName varchar,department varchar.
facultyregtable1 : ID int,FacultyName varchar,DeptName varchar.
我的 aspx 代码:
<asp:DropDownList ID="DropDownList1" runat="server" Height="20px" Width="147px">
</asp:DropDownList>
我的 C# 代码:
public partial class studentfeedbackarea : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1ConnectionString1"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
SqlCommand cmd = new SqlCommand("select FacultyName from facultyregtable1 where DeptName=(select department from Studentregtable where UserName=' " + Session["new"].ToString() + " ')", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
con.Close();
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "FacultyName";
DropDownList1.DataValueField = "FacultyName";
DropDownList1.DataBind();
}
}
下拉列表中未显示任何值。为什么?我的代码中有任何错误吗?