Welcome to WebmasterWorld Guest from 3.80.38.5

Forum Moderators: ocean10000

Message Too Old, No Replies

2 Multi Select List Boxes

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

New User

5+ Year Member

joined:May 27, 2010
posts: 2
votes: 0


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.
5:34 pm on June 24, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:732
votes: 0


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members