Let's say I have this table:
[B]Publisher Author rating1 rating2 rating3 rating4 rating5[/B]
Sams John 5 na 4 4
Sams Mary 3 5 5 5 5
Sams Kevin 1 4 4 5
Sams Denise 5 5 3 5 5
Let's say I have two Listboxes:
Listbox1 contains these items
rating1
rating2
rating3
rating4
rating5
Listbox2 contains these items
1
2
3
4
5
I have my code partially working where the user selects let's say rating2 from Listbox1 and '4' from Listbox2. The fields that get pulled from the database are:
[B]Publisher Author rating1 rating2 rating3 rating4 rating5[/B]
Sams Kevin 1 4 4 5
I can also select rating1 and rating2 from Listbox1 and let's say '5' fom Listbox2. These fields are pulled:
[B]Publisher Author rating1 rating2 rating3 rating4 rating5[/B]
Sams Denise 5 5 3 5 5
Here is the code I'm using:
if (ListBox2.SelectedIndex != 0 && ListBox2.SelectedIndex != -1)
{
for (int j = 0; j < ListBox1.Items.Count; j++)
{
if (ListBox1.Items[j].Selected)
{
for (int i = 0; i < ListBox2.Items.Count; i++)
{
if (ListBox2.Items[i].Selected)
{
sbQuery.Append(" AND " + ListBox1.Items[j].Value + "= '" + ListBox2.Items[i].Value + "'");
}
}
}
}
else
{
sbQuery.Append(" AND 1=1");
}
searchDetails.DataSource = null;
searchDetails.DataBind();
view.RowFilter = sbQuery.ToString();
GridView1.DataSource = view;
GridView1.DataBind();
What I cannot get to work is if I select let's say 'rating4' from Listbox1 and I select '4' and '5' from Listbox2, no fields are pulled. Shouldn't these fields be displayed. How can I modify my code to make it work? Please help!!!! Thanks.
[B]Publisher Author rating1 rating2 rating3 rating4 rating5[/B]
Sams John 5 na 4 4
Sams Mary 3 5 5 5 5
Sams Kevin 1 4 4 5
Sams Denise 5 5 3 5 5