禁用DropDownList某一选项

一个下拉式菜单,某一个项目需要禁用,不能让用户选择。 其实安全的做法,是不让这个选择显示于下拉式菜单中,这样用户不管怎样也选择不了。

另外就是让这个选择显示,在下拉菜单有异动时,或提交数据时,提示用户不能选择这个选项。

上面的演示,"Run"选项,用户是无法选择的。

功能实现,写一个方法,

DisAbleDropDownListItem
 public void DisAbleDropDownListItem(DropDownList ddl)
        {
            foreach (ListItem li in ddl.Items)
            {
                if (li.Value == "1" || li.Text == "RUN")
                {
                    li.Attributes.Add("disabled""disabled");
                }
            }
        }

在Page_Load时,应用这个方法。

原文地址:https://www.cnblogs.com/insus/p/2703303.html