0

Hi all,

The following link http://www.codeproject.com/KB/webforms/disableListItems.aspx disables items 1 and 2 from the checkboxlist if the user selects checkbox item 3.

Can someone PLEASE tell me how i could change the code in this link to work for ListBox.

So if I had 5 items in the lisr box (below)

AA

BB

CC--disable

DD--disable

EE

It will disable items CC and DD. But this will be disabled when the form loads...

please help me? please...

3
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by Ramesh S
0

IE does not support 'disabled' option in ListBox and Comboboxes.
The ListBox is actually rendered as <SELECT> html element and the ListItem is rendered as <option> element at run time in browsers.


From this thread, the following statements can be used to disable an item in ListBox

ListItem item1 = ListBox1.Items.FindByValue("CC");
    item1.Attributes.Add("disabled", "");

or you can do it like

ListBox1.Items.FindByValue("DD").Attributes.Add("disabled", "disabled");

Please note that above code will work only in FireFox and will not work in IE.

You need to find alternate way to do this.

You can see a third part components in this link: http://demos.telerik.com/aspnet-ajax/listbox/examples/clientside/addremovedisable/defaultcs.aspx

But this component renders the list as <LI> elements which gives you a ListBox effect.

Also have a look at these links.

http://www.lattimore.id.au/2005/07/01/select-option-disabled-and-the-javascript-solution/
http://elmicoxcodes.blogspot.com/2007/05/activating-option-disabled-in-ie.html
http://stikiflem.wordpress.com/2008/09/01/disable-combobox-items-in-ie/

Edited by Ramesh S: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.