Disable Items in Checkbox List

Posted on 2008-10-22
Last Modified: 2012-05-05

I have a checkboxlist which is populated from a database. I am also added a item to the checboxlist called any:
cblFundTypeAdvised.Items.Insert(0, New ListItem("Any", "-1"))

What i am trying to do is if there is a -1 value in the database then it disables all other items in the checkbox list except for this one (the Any one which is added manually)

Any ideas?
Question by:patelajk
  • 3
  • 2

Accepted Solution

AmarIs26 earned 125 total points
ID: 22774830
If you are doing databind then you can set the visible property to false or true depending on the value column in the dataitem. I forget the exact expression but something like this
Enable='<% Eval("valueColumn") != -1 %>'
however if you are looping throw the items manually and adding then to the Checkbox list then you can do this in the prerender event

for(int i=0; i< cblFundTypeAdvised.Items.Count; i++)


   ListItem item =  cblFundTypeAdvised.Items[i];

   if(item.Value == "-1")


      item.Enabled = false;



Open in new window


Expert Comment

ID: 22774841
Sorry you also need to use this if statement
if(item.Text != "Any" && item.Value == "-1")


Author Comment

ID: 22774898
tried this but it disables the ANY checkbox litem only.... i want it to disable the other checkbox items and leave the ANY enabled

Expert Comment

ID: 22775123
Well the above should do it. If current item is not "Any" and value is "-1" then it should disable.
You can try putting the else statement
  item.Emabled = true;

Author Closing Comment

ID: 31508673
Got me started.... thanks for that

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code works but how can I download the file? 20 67
Allow space in this pattern 2 48
Tool Box 2 35
C#  Radio button search for Date not DateTime 4 35
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: (…

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now