【发布时间】:2016-08-11 12:33:20
【问题描述】:
我有一个需要通过 SQL 填充的 asp.net 形式的 DropdownList。我在我的Page_Load() 中使用了ScriptManager,并且由于这个下拉列表没有被填充。我需要使用ScriptManager,因为我使用的是AjaxCalendarExtender。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = dba.getNames();
ddNames.DataSource = ds.Tables["EMPLOYEE"].DefaultView;
ddNames.DataTextField = "Username";
ddNames.DataValueField = "Username";
ddNames.DataBind();
}
if (ScriptManager.GetCurrent(Page) == null)
{
Page.Form.Controls.AddAt(0, new ScriptManager());
}
}
DB_Access.cs 中的 getNames() 函数
public DataSet getNames()
{
if (conn.State.ToString() == "Closed")
{
conn.Open();
}
SqlCommand newCmd = conn.CreateCommand();
newCmd.Connection = conn;
newCmd.CommandType = CommandType.Text;
newCmd.CommandText = "Select DISTINCT Username from dbo.EMPLOYEE";
SqlDataAdapter da = new SqlDataAdapter(newCmd);
DataSet ds = new DataSet();
da.Fill(ds, "EMPLOYEE");
conn.Close();
return ds;
}
【问题讨论】:
-
有趣。提问者在哪里
-
代码不会将值返回到下拉列表。显示一个空的下拉列表。我该如何解决?
标签: c# asp.net scriptmanager