Forum Moderators: open

Message Too Old, No Replies

2 Multi Select List Boxes

         

macfam929

4:44 pm on Jun 24, 2010 (gmt 0)

10+ Year Member



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.

marcel

5:34 pm on Jun 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi macfam929, welcome to WebmasterWorld!

Check what's being sent to SQL Server with the Profiler, you'll find that (unfortunately) it's not possible to use IN with parameterized queries as you'd like.

A search for "select in" parameterized query will give you a number of (in my opinion) unsatisfsactory workarounds, but hopefully it will help you find a suitable solution.