Link to home
Start Free TrialLog in
Avatar of AngieWill

asked on

How to disable some items of a dropdownlist with IE 6?

Hi Experts!

I wanted to disable some items of a dropdownlist. I found a solution but this solution works only with IE 8 and not with IE 6.

My code:

dropdownList1.DataSource = DS;

foreach (DataRow Row in DS.Tables[0].Rows)
            if (Row["field1"].ToString() == "N")
                dropdownList1.Items[DS.Tables[0].Rows.IndexOf(Row)].Attributes.Add("disabled", "disabled");

Do you have an idea for IE 6?

Avatar of Mark Steggles
Mark Steggles
Flag of United States of America image

Hmm not sure if you can in js but you could use css to hide them in ie6 like this:

<!--[if IE 6]>
Special instructions for IE 6 here

Avatar of CaptRespect

IE 6 doesn't support foreach loops so you'll have to change it to a normal loop

something like:
for (i = 0; i < DS.Tables[0].Rows.length; i ++) {
     Row = DS.Tables[0].Rows[i];
     if (Row["field1"].ToString() == "N")
                dropdownList1.Items[DS.Tables[0].Rows.IndexOf(Row)].Attributes.Add("disabled", "disabled");

Open in new window

Please disregard my comment as I misread your question :O
CaptRespect, the foreach loop is actually being executed in the c# code-behind, not in js.
The problem is that ie6 completely ignores the disabled property on option items.

There is no easy solution for what you're looking for, but there are a couple of options.

1) This guy came up with a workable though complex solution if you NEED to get the disabled appearance, through javascript and basically "tricking" good old ie6.
2) If you just set the .Enabled property on the listitem, they won't show up at all.  This of course stops them from being able to be selected, since they're not there, but doesn't give the effect you're looking for.
Avatar of AngieWill


Thank Snarf0001 for your help.
This link has been help me but I have another problem now : I had a postback for this dropdownlist and with this code, no postback is fired. Do you have an idea?
Avatar of knx007

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey AngieWill, sorry for the delay, was caught in meetings.
knx007, postback refers to the page submission back to the server.

Angie, do you mean you had the dropdown hooked up to autopostback on change?
Should still be able to get this working, but pls post your code so I can see how you're doing it.
If its postback is trigged by the onchange event, that means asp generate a "onchange=" attribute on the select box, so try my solutions, it works !
Thnaks for your help.