Link to home
Start Free TrialLog in
Avatar of Ed
EdFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Make Certain Items in Dropdown List Unselactable.


I have a dropdown list populated by a data source.

Some of the items I want to be Greyed out and un-selectable.   What's the best way to achieve this?

 <asp:DropDownList ID="ddlIVType" runat="server" AppendDataBoundItems="True"
                                            DataSourceID="DSIVType" DataTextField="IVTYPE"
                                            DataValueField="IVTYPEID" >
                        <asp:ListItem Value="0">-Select-</asp:ListItem>

Open in new window

Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Simply filter them out of the datasource. Unless you have very special needs, providing a list in which some items cannot be selected is a very strange idea. The raison d'être of a DropDown is "here is what you can chose from", so it normally makes no sense to display items that are not selectable.
Avatar of Ed


Jacques - its not a strange idea.....filtering them out is easy. You've missed the point.
The reason why I'd like to do this is that the dropdown list is data bound. Some of the options I do not want selected already exist in the database so I need them to be available to the dropdown if a selected record contains an old have I no longer want selectable when creating a new record.
Avatar of AndyAinscow
Flag of Switzerland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Data bound means that you build a set of data, either through a query or some other mechanism. This is where you can filter them. As Andy says, it is not possible, because it makes no sense for the user, and a ListBox is a tool for the user, not the programmer.
Avatar of Ed


Great Solution.