Solved

Disable Items in Checkbox List

Posted on 2008-10-22
5
305 Views
Last Modified: 2012-05-05
Hi

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?
0
Comment
Question by:patelajk
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
AmarIs26 earned 125 total points
Comment Utility
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

0
 
LVL 6

Expert Comment

by:AmarIs26
Comment Utility
Sorry you also need to use this if statement
if(item.Text != "Any" && item.Value == "-1")

0
 

Author Comment

by:patelajk
Comment Utility
tried this but it disables the ANY checkbox litem only.... i want it to disable the other checkbox items and leave the ANY enabled
0
 
LVL 6

Expert Comment

by:AmarIs26
Comment Utility
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
else
{
  item.Emabled = true;
}
0
 

Author Closing Comment

by:patelajk
Comment Utility
Got me started.... thanks for that
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

8 Experts available now in Live!

Get 1:1 Help Now