ASP.Net/C# - Is there a way to make a group of checkboxes mutually exclusive?

Hi all.  This is not an easy one I beleive.  I am creating radiobuttons currently with a groupname all in code dynamically.  Well the user now needs to be able to deselect one.  I know I could create one more control with "none" as an option.  Is there a way though to create checkboxes that will do this?  Through my loop I create controls such as this in a control array and you can see I dynamically create its ID as well:

cbl.ID = "cbl" + count; //i.e. ID = rbl1_23
cbl.Attributes.Add("Price", formattedPriceControl);
cbl.Attributes.Add("ItemID", row["ItemID"].ToString());
myControls.Add(cbl.ID);
lit.Text = sbAddBookItems.ToString();
this.Form1.Controls.Add(lit);
this.Form1.Controls.Add(cbl);
cbl = new CheckBox(); //reset the CheckBoxList to a new one
lit = new Literal();
sbornstein2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VelioCommented:

to do this client-side, one solution is to add the following script to your page
    <script language="javascript" type="text/javascript">
        function ExclusiveCheck(checkBox)
        {
            for (i = 0; i < myCheckboxes.length; i++)
            {
              if (document.getElementById(myCheckboxes[i]) != checkBox)
                document.getElementById(myCheckboxes[i]).checked = false;
            }
             
        }
    </script>

then add the following lines in the loop when you create your checkboxes:

cbl.Attributes.Add("onclick", "ExclusiveCheck(this);");
Page.RegisterArrayDeclaration("myCheckboxes", String.Format("'{0}'", cbl.ID));


-- OR --
have your checkboxes AutoPostBack = true and do it on the server-side, which is rather undesirable in my opinion.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
divinewind80Commented:
My suggestion would be to use Javascript to accomplish your task.  Is this an option?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.