使下拉列表项不可选择 [英] make drop down list item unselectable

查看:32
本文介绍了使下拉列表项不可选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,其中包含多个用于生成报告的选项.根据帐户类型,用户有一些应该可见但不可选的选项(作为他们升级的激励).

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.

任何帮助将不胜感激.

推荐答案

不确定您是否还在为此寻找答案?

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

Mark Redman 的回答 很棒,如果您可以在 aspx 页面中定义选择列表,但是如果您绑定 drop显然你不能动态地列出来.

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.

我成功地使用以下方法实现了您所追求的结果(不确定是否支持完整的浏览器,但适用于较新版本的 IE)

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.

这篇关于使下拉列表项不可选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆