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...

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/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.