I have two Multi Select Listboxes.
The selections of the first list box are supposed to fill in the second list box from a sql database.
When one thing is selected in the first list box it populates the second list box with all data except for the first piece of data, however as soon as multiple selections are made the second list box goes blank.
My current code is:
private void LoadSequence(string partlist)
{
SqlCommand cmd = new SqlCommand("", conn);
SqlDataReader rdr;
try
{
conn.Open();
cmd.CommandText = "SELECT DISTINCT apnRoutingMaster.description, apnRoutingMaster.seq_SAP " +
"FROM apnRoutingMaster INNER JOIN apnProdMaster ON apnRoutingMaster.prod_id = apnProdMaster.prod_id " +
"WHERE (apnProdMaster.vendor_code = '1000035') AND (apnRoutingMaster.description IS NOT NULL) AND (apnProdMaster.shortname IN (@partlist)) " +
"ORDER BY apnRoutingMaster.seq_SAP";
cmd.Parameters.AddWithValue("@partlist", partlist);
rdr = cmd.ExecuteReader();
rdr.Read();
lbxSteps.DataSource = rdr;
lbxSteps.DataBind();
rdr.Close();
conn.Close();
}
catch (Exception e3)
{
}
finally
{
if (conn.State != ConnectionState.Closed)
conn.Close();
}
}
protected void lbxPartType_SelectedIndexChanged(object sender, EventArgs e)
{
string lbxPartTypeALL = "";
foreach (ListItem li in lbxPartType.Items)
{
if (li.Selected)
{
lbxPartTypeALL += li.Value + ",";
}
}
string lbxPartTypeALLTrim = lbxPartTypeALL.TrimEnd(',');
LoadSequence(lbxPartTypeALLTrim);
}
Any help that you can give would be greatly appreciated! I have been struggaling with this problem for several weeks now.