[Last Call] Learn how to a build a cloud-first strategyRegister Now


Enable CheckBoxList item

Posted on 2005-05-11
Medium Priority
Last Modified: 2010-04-07
I have a check box list with 7 boxes. I would also like to have one of the item to be disabled whereas the other boxes are always enabled.  

I am looking for this type of logic.


What is the correct syntax for both of the above?

Question by:samjaiswal
  • 4
  • 3
LVL 35

Expert Comment

ID: 13982740

To disable a checkbox:

document.formname.checkboxname.disabled = true;

To set a checkbox to checked:

document.formname.checkboxname.checked= true;

It is cas sensitive so make sure you enter your formname for "formname" and your checkboxname for "checkboxname" with the correct caps

Author Comment

ID: 13985277
I believe this code will help me to disable checkboxlist,
Actually I need to disable one of the item from the checkboxlist not the whole checkbox.


LVL 35

Expert Comment

ID: 13988276
A check box list of 7 checkboxes is actually just 7 checkboxes.

Look at the THML that is produced and post that and I can give you more specifics for your sitiuation
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.


Author Comment

ID: 13990504
A CheckboxList control can have multiple checkbox under single checkboxlist.

<TD style="WIDTH: 347px; HEIGHT: 191px" vAlign="top" align="left"><INPUT style="WIDTH: 76px; FONT-FAMILY: Arial; HEIGHT: 24px" onclick="checkallStrike(true)"
      type="button" value="Select All">
  <asp:checkboxlist id="CheckBoxList1" runat="server" Font-Names="Arial">
      <asp:ListItem Value="Suspension">Suspension</asp:ListItem>
               <asp:ListItem Value="Restoration">Restoration</asp:ListItem>
      <asp:ListItem Value="DLC">DLC</asp:ListItem>

I can add items like Suspension,Restoration and DLC.
I want to Hide one of the listitem like DLC .

Hope this gave you a beeter idea what I'm trying to do.
LVL 35

Expert Comment

ID: 13990854
That is what I thought you were doing.  But if you look at the generated HTML you will see that it generates separte checkboxes for each <asp:ListItem> element.  ASP then treats as a list, but the page itself sees separate checkboxes.

For example your code above creates this HTML:

<table id="CheckBoxList1" border="0" style="font-family:Arial;">
            <td><input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1:0" /><label for="CheckBoxList1_0">Suspension</label></td>
            <td><input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1:1" /><label for="CheckBoxList1_1">Restoration</label></td>

            <td><input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1:2" /><label for="CheckBoxList1_2">DLC</label></td>

So assuming that you wanted to disable the first checkbox then the syntax could be one of

document.getElementById("CheckBoxList1_0").disabled = true;


document.Form1.CheckBoxList1:0.disabled = true;

(Personally I would use the first syntax)

Also since you are using ASP.NET you can have the server assign this value instead of javascript (i.e. in the code-behind)

Author Comment

ID: 13996482
Thanks a lot.

Can we also make visible false ?
LVL 35

Accepted Solution

mrichmon earned 2000 total points
ID: 13996631
Setting visible to false in .NET makes it not even render on the page.

Setting theCSS  class/style to display:none; makes it render but not be visible nor take up any space to the user.

Depends on what you want....

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

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