Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

asp.net - make drop down list item unselectable

I have a dropdownlist which has several options for generating reports. Based on the type of account the user has certain options which should be visible but not selectable (as an incentive for them to upgrade).

I was wondering if anyone knew of a way to accomplish this.

The permissions are already in place i just need assistance with making certain items unselectable.

Any help would be much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Not sure if you are still looking for an answer for this?

Mark Redman's answer is great if you can define the select list in the aspx page, however if you bind the drop down list dynamically obviously you cannot.

I had success using the following to achieve the result you are after (not sure on full browser support but works in newer versions of IE)

foreach ( ListItem item in dropdownlist.Items )
{
    if ( [item should be disabled condition] )
    {
        item.Attributes.Add( "disabled", "disabled" );
    }
}

This will render your disabled elements greyed out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...