?
Solved

Disable CheckboxList Items

Posted on 2006-03-24
3
Medium Priority
?
910 Views
Last Modified: 2008-01-09
I have a checkboxlist with several items checked by default.  Is there any way to prevent a user from unchecking these items?
0
Comment
Question by:abenage
3 Comments
 
LVL 4

Expert Comment

by:g_johnson
ID: 16281900
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.
0
 
LVL 7

Accepted Solution

by:
Focusyn earned 2000 total points
ID: 16282260
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.
0
 
LVL 1

Author Comment

by:abenage
ID: 16282493
OK.  Thanks for the insight.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Integration Management Part 2
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question