I have a problem with the retrieval of multiple checkbox values in my program. So as you can see below, I'm trying to retrieve from my database based on a set of values from the checkboxlist.
If I select ONE check box value, the database would be able to retrieve the item, however if I select MORE THAN ONE checkbox value, nothing will appear. Can someone help me please? I've spent quite some time on it.
I've seen other solutions but it doesn't seem to have helped me. Thank you.
protected void chkBoxCategories_SelectedIndexChanged(object sender, EventArgs e)
{
// Create the list to store.
List<String> YrStrList = new List<string>();
// Loop through each item.
foreach (ListItem item in chkBoxCategories.Items)
{
if (item.Selected)
{
// If the item is selected, add the value to the list.
YrStrList.Add(item.Value);
}
else
{
// Item is not selected, do something else.
}
}
// Join the string together using the ; delimiter.
Session["UPCategories"] = String.Join(", ", YrStrList.ToArray());
}
The following code is on the other page:
SqlDataSource1.SelectCommand = "SELECT sf.*, sfc.* FROM SkillsFuture sf INNER JOIN SkillsFutureCategory sfc ON sfc.SFCatID = sf.fkSFCatID WHERE sfc.SFCatName IN (@catnames) AND sf.SFPrice BETWEEN @min AND @max AND sf.SFCertStatus='Verified'";
SqlDataSource1.SelectParameters.Add("catnames", Session["UPCategories"].ToString());
SqlDataSource1.SelectParameters.Add("min", Convert.ToDecimal(Session["UPBudgetMin"]).ToString());
SqlDataSource1.SelectParameters.Add("max", Convert.ToDecimal(Session["UPBudgetMax"]).ToString());
SqlDataSource1.DataBind();