mugsey
asked on
Loop though checkbox list asp.net c#
I have a checkbox list control that contains about 20 checkboxes that capture an individuals interests. For example, fishing, music, cookery etc
I need to use these checkboxes as a search for a dynamic query to sql server. So if "cookery" is checked then I alter my sql query like this
if (checkbox number 23 is checked) //it must be cookery so add it to our WHERE clause
{
oClause.column = "[Cookery]";
oClause.operand = " = ";
oClause.criteria = "1";
cClauses.Add(oClause);
}
What is the best way to loop through the checkbox list to add checked items to my sql query?
I need to use these checkboxes as a search for a dynamic query to sql server. So if "cookery" is checked then I alter my sql query like this
if (checkbox number 23 is checked) //it must be cookery so add it to our WHERE clause
{
oClause.column = "[Cookery]";
oClause.operand = " = ";
oClause.criteria = "1";
cClauses.Add(oClause);
}
What is the best way to loop through the checkbox list to add checked items to my sql query?
ASKER
Thanks but I have about 20 checkboxes how do I know if say checkbox20 is equal to cookery?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
{
if (ctrl is CheckBox)
{
CheckBox chk = (CheckBox)ctrl as CheckBox;
if (chk.Checked)
{
//Code to add to query
}
}
}