make drop down list item unselectable

后端 未结 9 506
天涯浪人
天涯浪人 2020-11-30 07:26

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

相关标签:
9条回答
  • 2020-11-30 08:06

    I had this same problem and tried to use the first answer posted, but it didn't work for me. I then changed the first post to:

    foreach ( ListItem item in dropdownlist.Items )
    {
      if ( [item should be disabled contdition] )
      {
         item.Enabled = false;
      }
    }
    

    and it worked for me.

    0 讨论(0)
  • 2020-11-30 08:09

    You can use a required field validator and set the initial value property to the value of the item in the drop down list you do not want selectable.

    <asp:RequiredFieldValidator ID="RequiredFieldValidator" runat="server"
                            ErrorMessage="" ControlToValidate="DropDown" InitialValue="Unselectable Item"></asp:RequiredFieldValidator>
    
    0 讨论(0)
  • 2020-11-30 08:09

    You could try this

    myDropDownList.Items.FindByValue("ReportValue").Attributes.Add("disabled", "disabled");
    
    0 讨论(0)
提交回复
热议问题