0
我想从我的数据库中获取值来填充下拉列表。动态下拉列表问题
我已经调试下面的函数,它带来了预期的结果,但仅存储最后一个返回值:
public static string GetAllPlacements(string placementLocation)
{
string returnVal = null;
using (SqlConnection sqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["websiteContent"].ConnectionString))
{
sqlCon.Open();
string SQL = "SELECT DISTINCT " + placementLocation + " FROM Placements";
using (var CMD = new SqlCommand(SQL, sqlCon))
{
using (var DR = CMD.ExecuteReader())
{
while (DR.Read())
{
returnVal = DR[selectField].ToString();
}
}
}
sqlCon.Close();
}
return returnVal;
}
例如有两个结果,伦敦和巴黎,但“returnVal”只存储巴黎。
的我这个数据绑定到下拉列表:
private void refreshLocation()
{
ddlLocation.DataSource = Placements.GetAllPlacements("Placement_Location");
ddlLocation.DataBind();
ddlLocation.Items.Insert(0, new ListItem("-- Please Select --", "0"));
}
在下拉列表中选择巴黎出现这样的:
P
A
R
I
S
取而代之的是:
London
Paris
任何帮助,将不胜感激。
什么是'selectField'价值? – 2013-04-06 22:28:45