I'm brain tired and stumped so wanted to see if anyone knows a better way to do this:
I have 4 checkboxes that a user can select none, one, or all, or any combo. Then in the code behind I want to check all the CheckBoxes and if it's been selected then take it's value (text) and assign it to 1 string and separate it with a comma as necessary.
This works great but assigns all the .Text whether or not the items have been checked.
if (CheckBox1.Checked || CheckBox2.Checked || CheckBox3.Checked || CheckBox4.Checked)
{
ClientString = CheckBox1.Text + ", " + CheckBox2.Text + ", " + CheckBox3.Text + ", " + CheckBox4.Text;
}
I'm staring at it and I know the solution is really simple but I'm too tired to think clearly right now and wanted to find out what I'm doing wrong. Code is C# (ASP.NET).
How do I poll the 4 CheckBoxes and if it's checked then assign it's value to the string and ignore it if it isn't checked?
Thanks.