mugsey
asked on
foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.CheckBoxList'
I am getting the error
foreach statement cannot operate on variables of type 'System.Web.UI.WebControls .CheckBoxL ist'
When I try and run this code
foreach (Control ctrl in this.chkListMyInterests)
{
if (ctrl is CheckBox)
{
CheckBox chk = (CheckBox)ctrl as CheckBox;
if (chk.Text == "Maritime")
{
if (chk.Checked)
{
//maritime is included in the search criteria
oClause.column = "[maritime]";
oClause.operand = " = ";
oClause.criteria = "1";
cClauses.Add(oClause);
}
}
etc etc etec
What is the right syntax please
foreach statement cannot operate on variables of type 'System.Web.UI.WebControls
When I try and run this code
foreach (Control ctrl in this.chkListMyInterests)
{
if (ctrl is CheckBox)
{
CheckBox chk = (CheckBox)ctrl as CheckBox;
if (chk.Text == "Maritime")
{
if (chk.Checked)
{
//maritime is included in the search criteria
oClause.column = "[maritime]";
oClause.operand = " = ";
oClause.criteria = "1";
cClauses.Add(oClause);
}
}
etc etc etec
What is the right syntax please
ASKER
Hi
But I need to check the name of each checkbox, for example
if (chk.Text == "cookery")
{
//amend sql query
}
How can I do that
But I need to check the name of each checkbox, for example
if (chk.Text == "cookery")
{
//amend sql query
}
How can I do that
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Actually I have sorted it using
foreach (ListItem ctrl in this.chkListMyInterests.It ems)
{
if (ctrl.Text == "Cookery")
{
if (ctrl.Selected)
{
//cookery is included in the search criteria
foreach (ListItem ctrl in this.chkListMyInterests.It
{
if (ctrl.Text == "Cookery")
{
if (ctrl.Selected)
{
//cookery is included in the search criteria
Glad it's solved.
Don't forget to close the question
Don't forget to close the question
foreach (Control ctrl in this.chkListMyInterests.It
example:
foreach (ListItem htlRmItem in cblRoomFacilities.Items)
{
if (htlRmItem.Selected == true)
{
cmdInsertRmFac.Parameters.
cmdInsertRmFac.Parameters.
cmdInsertRmFac.Parameters.
}
}