473,387 Members | 1,510 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,387 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 19 '05 #1
2 1445
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 19 '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 19 '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...
1
by: rbscheer | last post by:
Hi. Is there any way to count how many items are selected on a CheckBoxList control without iterating throug the items? I have a For...Next loop that only needs to be taken into action if the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.