-1
我使用包含下拉list.Now我不想寫相同的代碼從database.I獲取相同的數據C#使得在asp.net應用程序是嘗試這種代碼,但它不工作無法將數據與下拉列表綁定?
protected void Page_Load(object sender, EventArgs e)
{
DataTable DT = sel_obj.select_Dept_Name();
departmentDrop.DataSource = DT;
departmentDrop.DataMember = "Department_Name";
departmentDrop.DataBind();
}
public DataTable select_Dept_Name()
{
module c = new module();
c.DB_Connection();
if (c.con.State == ConnectionState.Open)
{
c.con.Close();
c.con.Open();
}
DataSet DS = new DataSet();
string QRY = "";
QRY = "SELECT Department_Name FROM Department_Master";
SqlDataAdapter DA = new SqlDataAdapter(QRY, c.con);
DA.Fill(DS);
DataTable DT = DS.Tables[0];
return DT;
}
'不工作'不是一個正確的問題。請更詳細地說明您面臨的問題 –
add'departmentDrop.ValueMember =「Department_Name」'and'departmentDrop.DataBind();':) – zey