473,395 Members | 1,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

disable items in CheckBoxList

sql
Hi all,
I am using a CheckBoxList control on my aspx page that I bind to an array
at runtime. After I databind it, I check two of the items in the
CheckBoxList controls. Now I also need to disable these two items so that
users can't uncheck them. But I don't know how to disable individual items.
Can you please help me achieving this(preferably at runtime)?

Thanks in advance.
Nov 17 '05 #1
2 3443
I am sure that this can be improved upon, but here is something that works.
To test the code out (listed below), simply add a CheckBoxList control to a
web form (name = "clb") and add the code below to the Page_Load event. When
you run the form, there will be 4 items which start out as unchecked. When
you click on an item, it will become checked and you will not be able to
uncheck it. This should give you a base to work from.

HTH,
Jody

__________________

Dim x() As String = {1, 2, 3, 4}

Dim intCount As Integer

Dim strItemName As String

Dim strScript As String

clb.DataSource = x

clb.DataBind()

For intCount = 0 To x.Length - 1

strItemName = clb.ClientID & "_" & intCount.ToString

strScript = "<script language = jscript for =" & strItemName & " event
=""onclick"">" & ControlChars.CrLf

strScript &= strItemName & ".checked='true';" & ControlChars.CrLf

strScript &= " </script> " & ControlChars.CrLf

RegisterClientScriptBlock("script" & intCount.ToString, strScript)

Next

___________________
"sql" <do*******@nospaml.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Hi all,
I am using a CheckBoxList control on my aspx page that I bind to an
array at runtime. After I databind it, I check two of the items in the
CheckBoxList controls. Now I also need to disable these two items so that
users can't uncheck them. But I don't know how to disable individual
items. Can you please help me achieving this(preferably at runtime)?

Thanks in advance.

Nov 17 '05 #2
sql
Thanks.

"Jody Gelowitz" <jg**************@blah.leevalley.com> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
I am sure that this can be improved upon, but here is something that works.
To test the code out (listed below), simply add a CheckBoxList control to a
web form (name = "clb") and add the code below to the Page_Load event.
When you run the form, there will be 4 items which start out as unchecked.
When you click on an item, it will become checked and you will not be able
to uncheck it. This should give you a base to work from.

HTH,
Jody

__________________

Dim x() As String = {1, 2, 3, 4}

Dim intCount As Integer

Dim strItemName As String

Dim strScript As String

clb.DataSource = x

clb.DataBind()

For intCount = 0 To x.Length - 1

strItemName = clb.ClientID & "_" & intCount.ToString

strScript = "<script language = jscript for =" & strItemName & " event
=""onclick"">" & ControlChars.CrLf

strScript &= strItemName & ".checked='true';" & ControlChars.CrLf

strScript &= " </script> " & ControlChars.CrLf

RegisterClientScriptBlock("script" & intCount.ToString, strScript)

Next

___________________
"sql" <do*******@nospaml.com> wrote in message
news:eh**************@TK2MSFTNGP09.phx.gbl...
Hi all,
I am using a CheckBoxList control on my aspx page that I bind to an
array at runtime. After I databind it, I check two of the items in the
CheckBoxList controls. Now I also need to disable these two items so that
users can't uncheck them. But I don't know how to disable individual
items. Can you please help me achieving this(preferably at runtime)?

Thanks in advance.


Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sql | last post by:
Hi all, I am using a CheckBoxList control on my aspx page that I bind to an array at runtime. After I databind it, I check two of the items in the CheckBoxList controls. Now I also need to disable...
1
by: Bobby | last post by:
I want to enable/disable individual items in a checkedlistbox. I have a field in a db that tells me whether the item should be enabled. I am just not sure how to disable an item in the...
3
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception...
2
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript...
8
by: Steven Garrad | last post by:
Hi All I have a custom class that is derived from the PictureBox class. One of the properties from the PictureBox class is "SizeMode" and in my custom class I want to disable the user from being...
0
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi (asp.net 2.0, vb.net, SQL Server 2005 Express) I have a Form where users can select multiple preferences via a CheckListBox. Those items are stored in a SQL 2005 database and are related to...
2
by: kewldudehere | last post by:
Hi All, Is it Possible to disable or greyout some items in dropdownlist. My application is role based and want to disable selection of some items in dropdownlist based upon user role. But i want...
1
by: Bob | last post by:
Is there any practical way to disable items within a ListView control? I'd like to be able to 'filter' the list incrementally without actually removing anything (so I can remove the filter to get...
5
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.