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());
lit.Text = sbAddBookItems.ToString();
cbl = new CheckBox(); //reset the CheckBoxList to a new one
lit = new Literal();
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.


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;

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.


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
My suggestion would be to use Javascript to accomplish your task.  Is this an option?
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

From novice to tech pro — start learning today.