一個下拉式菜單,某一個項目需要禁用,不能讓用戶選擇。 其實安全的做法,是不讓這個選擇顯示於下拉式菜單中,這樣用戶不管怎樣也選擇不了。
另外就是讓這個選擇顯示,在下拉菜單有異動時,或提交數據時,提示用戶不能選擇這個選項。
上面的演示,"Run"選項,用戶是無法選擇的。
功能實現,寫一個方法,

public
void DisAbleDropDownListItem(DropDownList ddl)
{
foreach (ListItem li in ddl.Items)
{
if (li.Value == " 1 " || li.Text == " RUN ")
{
li.Attributes.Add( " disabled ", " disabled ");
}
}
}
{
foreach (ListItem li in ddl.Items)
{
if (li.Value == " 1 " || li.Text == " RUN ")
{
li.Attributes.Add( " disabled ", " disabled ");
}
}
}
在Page_Load時,應用這個方法。