Solved

Disable Items in Checkbox List

Posted on 2008-10-22
5
330 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
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

0
 
LVL 6

Expert Comment

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

0
 

Author Comment

by:patelajk
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
0
 
LVL 6

Expert Comment

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

Author Closing Comment

by:patelajk
ID: 31508673
Got me started.... thanks for that
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 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