I have a table with 4 rows of state checkboxes (NJ, CA, FL, etc)
The table has an ID and a runat="server" tag, and each checkbox has an 'ID' 'Text' and 'runat="server"' tag.
I tried to make a list like below in order to use in a query but it is not getting add
List<string> query = new List<string>();
foreach (Control c in tableStates.Controls)
{
if (c is CheckBox)
{
CheckBox chk = (CheckBox)c;
if (chk.Checked)
{
query.Add(chk.Text);
}
}
}
string line = string.Join(" or ", query.ToArray());
tbTest.Text = line;
I did this before with a table but I had used form1.Controls and it worked in the foreach, but I don't want to use form1 in case there are other checkboxes other than states on the page.
Is using form1.Controls my only option or what is going on here
Here is one row of table anyway
<table runat="server" id="tableStates">
<tr>
<td><asp:CheckBox ID="Checkbox0" Text="AL" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox1" Text="AK" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox2" Text="AZ" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox3" Text="AR" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox4" Text="CA" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox5" Text="CO" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox6" Text="CT" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox7" Text="DE" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox8" Text="DC" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox9" Text="FL" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox10" Text="GA" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox11" Text="HI" runat="server" /></td>
<td><asp:CheckBox ID="Checkbox12" Text="ID" runat="server" /></td>
</tr>
</table>