Saturday, February 25, 2012

multiple selection listbox as data control?

Hi, i have a listbox with multiple selection enabled, the end user uses this listbox to select what data they want to view eg. they select "green" to view all the green cars, "red" to select all the red cars etc.

i have the listbox as the control that is connected to the datasource (the sql used for it isselect * from cars_table where color =@.color

this works fine when one item in the listbox is selected, but when multiples are selected it does not work

what format does the=@.colorhave to be when multiples are selected? i've tried "green, red" "green + red" etc. but cannot seem to get it working

does anybody have any working examples that i can take a look at? it seems to be a common action, yet i cannot seem to find any documentation on how to get it to work

thanks in advance!

You will have to iterate through the selections and dynamically build your SQL

foreach (ListItem itemin ListBox1.Items)
{
if(item.Selected)
{
sql += " Or color = '" + item.Text +"'";
}
}

No comments:

Post a Comment