I have a list box that, upon loading the page, I would like to have selected the choices/options that are in the database. It's been a while since I've done anything with list boxes, so I'm a bit confused on how to fix the code for my GetClassification function that is meant to do exactly this. At the moment, it only selects one value in the listbox regardless of the vendor id is associated with more than one.
This is the code for the GetClassification function:
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();
}
}
}
}
@ClassIdsince you didn't declare this parameter in yourSqlCommand.