Avatar of Ed
Ed
Flag for United Kingdom of Great Britain and Northern Ireland asked on

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

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

ASP.NETVisual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Ed

8/22/2022 - Mon
Jacques Bourgeois (James Burger)

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

ASKER
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.
ASKER CERTIFIED SOLUTION
AndyAinscow

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jacques Bourgeois (James Burger)

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Ed

ASKER
Great Solution.