473,395 Members | 1,577 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.
Jul 21 '05 #1
2 1572
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.

Jul 21 '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.


Jul 21 '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...
0
by: Hyrum Mortensen | last post by:
Hi, I have a CheckBoxList that's populated by a database (Selected property is set based on data from the database). I want to disable rows that have the Selected property set to true (i.e....
1
by: Peter | last post by:
How can I check which items has been selected in CheckBoxList control when I bind data to it from SQL Server? The code I use works fine when I add manually items into checkboxlist control, but does...
7
by: Wayne Wengert | last post by:
I have a CheckBoxList with 11 items in the collection. I save the checked item to a SQL DB, A record is created for each item checked for the current customer.I want to redisplay checks in the...
0
by: Boris | last post by:
When I dynamically create CheckButtonList, I add ListItem(s) to my CheckButtonList object chkList chkList.Items.Add(new ListItem("My Text", "My Value")); The resulting HTML doesn't contain...
2
by: EnjoyLife | last post by:
I am new to ASP.NET and am trying to learn it the best that I can. I am trying to add some code in the If IntRowIndex > -1 statement to mark an item SELECTED before adding it to the CheckBoxList. ...
0
by: jeremy | last post by:
Had a tough time figuring this one out and couldn't find a good solution, so I thought I would post this and hopefully it will help someone out. When using DataBind to dynamically bind a list to...
1
by: MattB | last post by:
asp.net 1.1, vb.net I have a CheckBoxList that I need to conditionally disable one or more individual checkboxes from at runtime. I was hoping I could so something like:...
1
by: Bogdan | last post by:
Hi, I have a CheckBoxList on a page and an Object Data Source which expects values from the list as its select parameters. Is there a way to declaratively define select parameters to reference...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.