Disable CheckboxList Items

I have a checkboxlist with several items checked by default.  Is there any way to prevent a user from unchecking these items?
LVL 1
abenageAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

g_johnsonCommented:
I don't have .Net with me right now, but I think you can use the ItemCheck event and just set it back to checked if they try to uncheck it.
FocusynCommented:
The Checkboxlist is a table or array collection, and is not designed with the capability of setting different behavioral properties for individual items; In fact, it was designed for exactly the opposite reason: to allow the programmer to use a single control when all behaviors are identical for a ListItem collection.  To dynamically set behavior by item, you need to use the regular checkbox control instead of the CheckBoxList.  With the list, they will either all be enabled or disabled, and as far as I know it's impossible to change that without seriously manipulating the control via manual overloads etc.  

For the sake of time savings, here's what I would recommend:

You're using a data table or array to populate the items, and then using some dynamic property to decide which should be selectable or not selectable by the user.  The best practice would be to run through that table in a Loop manually adding an individual checkbox control with visible=true, checked=True/False depending, but enabled=true/false depending on whatever condition is deciding whether or not it should be modifiable. Visible=True and Enabled=False on the same control is what gives you that "grayed out" look.

Ok, so all that is a lot of iteration and possibly complex programming depending on your idividual skill level.  So in my classic style,
here's a Jerry-rig you can do if you just need to get this out quickly and can't or don't have time to do iterations and programatically created controls:

Add a panel to your page/form and use two checkboxlist controls.  Parse through your full datasource and at each record, insert into one of two arrays or tables, depending on whether or not the user should be allowed to modify that item.  Bind one checkboxlist to the 'userCANmodify' set and the other to the 'userCANTmodify' set.  Set both checkBoxLists to visible=True, and enabled=True for the one with datasoure 'userCANmodify' and enabled=False to the one bound to 'userCANTmodify' datasource.  Really the only downside to that is the sorting, but arguably, it makes it easier on the user because he or she doesn't have to look through a list of unchangable items to find the one he or she needs to change.

Only other workaround I know of for this is to either set the whole control to autopostback and keep re-checking the item when the user unchecks it, or explicitly resetting the collection to checked=true on form post.  Either of those are a bad idea because the user doesn't know unless you also add code to notify the user of such, and if you're going to spend that much time and coding, you may as well just do it properly with individual checkbox controls anyway.

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
abenageAuthor Commented:
OK.  Thanks for the insight.
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
Visual Basic.NET

From novice to tech pro — start learning today.