Reputation: 127
I have an ASP.net dropdownlist with four items,
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Selected="True" Value="0">Select Payment Method</asp:ListItem>
<asp:ListItem>Credit Card</asp:ListItem>
<asp:ListItem>PayPal</asp:ListItem>
<asp:ListItem>WeKea Store Gift Card</asp:ListItem>
</asp:DropDownList>
Is there a way to make "Select Payment Method" not selectable? I read through all the properties of an ASP.net DDL and I dont see anything of the sort.
Upvotes: 0
Views: 133
Reputation: 16701
You can use the disabled
attribute (see here) and apply it to the ListItem
:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Selected="True" Value="0" disabled="disabled">Select Payment Method</asp:ListItem>
<asp:ListItem>Credit Card</asp:ListItem>
<asp:ListItem>PayPal</asp:ListItem>
<asp:ListItem>WeKea Store Gift Card</asp:ListItem>
</asp:DropDownList>
This will render the option as greyed out and it will not be selectable. However, the selected=True
will override that and it will be displayed as selected when the page loads, which I think is what you want.
Upvotes: 1