我有一个列表框,在加载页面时,我想要选择数据库中的选项/选项。我已经用列表框做了一段时间,所以我对如何修正我的GetClassification函数的代码有点困惑,它意味着要做到这一点。目前,它仅在列表框中选择一个值,而不管该厂商ID是否与多个关联。基于数据库值预先选择列表框中的多个项目
这是GetClassification函数的代码:你要循环的所有项目,并设置Selected
,物业因此
protected void GetClassification(int VendorId)
{
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["AbleCommerce"].ToString()))
{
SqlCommand cmd = new SqlCommand("SELECT uidClassification FROM Baird_Vendors_Extension WHERE uidVendor = @VendorId", cn);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new SqlParameter("@VendorId", VendorId));
cn.Open();
using (IDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
vendorType.SelectedValue =reader["uidClassification"].ToString();
}
}
}
}
你不需要'@ ClassId'因为你没有申报在'SqlCommand'此参数。 – 2014-09-23 12:47:30
ASP.NET是我正在使用的。 – 2014-09-23 12:50:23