Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 6th, 2011, 09:06 PM
Authorized User
 
Join Date: Jan 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Disabling CheckBoxList

Hi,

Don't know if this is the right forum...

I'm able to disable an individual listitem of a checkboxlist on the client side. However, the text of that listitem does not get greyed out no matter what I tried. I want to grey out the text on the client side. Can it be done?

My markup goes something like this:

.
.
.
<td>
<asp:CheckBoxList ID="cbl1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="0">&nbsp;A&nbsp;&nbsp;&nbsp;&nbsp;</asp:ListItem>
<asp:ListItem Value="1">&nbsp;B&nbsp;&nbsp;&nbsp;&nbsp;</asp:ListItem>
<asp:ListItem Value="2">&nbsp;C</asp:ListItem></asp:CheckBoxList>
</td>


Here's how I disable my listitem:

var cbl = document.getElementById("<%=cbl1.ClientID%>");
var options = cbl.getElementsByTagName("input");

options[0].disabled = true;

I'm aware that the text of the listitem gets rendered as a label, but it does not have an id that I can refer to.

Thanks, if anyone can help.

Ed
 
Old September 7th, 2011, 08:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Quote:
Don't know if this is the right forum...
Probably not. This is a client side issue, so you may be better off posting questions like these in a JavaScript forum.

That said, this is easy to do with jQuery.

Code:
var allInputs = $('#<%=cbl1.ClientID%> input');
allInputs[0].disabled = true;
$(allInputs[0]).next().css('color', 'red');
This code gets all input elements, disables the first item and then finds the label using next() to which some CSS is applied; in this case to change the color of the text to red.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old September 7th, 2011, 12:20 PM
Authorized User
 
Join Date: Jan 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Disabling CheckBoxList

Hi Imar,

Thanks for the help. Greatly appreciated. I'll give it a try. Sorry for posting in the wrong forum.

Ed





Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckBoxList 123mehran ASP.NET 4 General Discussion 1 March 14th, 2011 06:09 PM
Checkboxlist epkgupta Visual Studio 2005 0 March 11th, 2008 05:31 AM
checkboxlist problems hanoisky ASP.NET 2.0 Basics 1 December 6th, 2006 06:04 PM
CheckBoxList stu9820 ASP.NET 1.0 and 1.1 Basics 10 May 25th, 2006 08:15 PM
CheckBoxList eddiema VS.NET 2002/2003 1 April 9th, 2004 09:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.