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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
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.
EdAuthor 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.
AndyAinscowFreelance programmer / ConsultantCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jacques Bourgeois (James Burger)PresidentCommented:
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.
EdAuthor Commented:
Great Solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.