Make Certain Items in Dropdown List Unselactable. Asp.net(vb)

Ed
Ed used Ask the Experts™
on
Hi

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>
                    </asp:DropDownList>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2015

Commented:
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.
Ed

Author

Commented:
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.
Freelance programmer / Consultant
Commented:
To the best of my knowledge - not possible.  It is either ALL are available or NONE.  The best you could do is prevent a new record being added when the user attempts to save it.
Top Expert 2015

Commented:
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.
Ed

Author

Commented:
Great Solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial