Solved

<asp:DropDownList>  OnSelectedIndexChanged

Posted on 2004-09-01
2
268 Views
Last Modified: 2012-05-05

I have a databound <asp:DropDownList> so it immediately has the first item from the database as the first ListItem:

<option value="1">Desktops</option>
<option value="2">Notebooks</option>
<option value="3">Monitors</option>

  What do I do so that I can make something that is an equivalent to:
 <option>--</option>  that has no value?

The reason I am asking is because if the first item from the database (Desktops) is the one the user wants to select then I can't get it to do a OnSelectedIndexChanged.  I figure if it shows a blank ListItem then the user will have to change the index to select Desktops and trigger the event.

I'd appreciate any solution to this--either some kind of <option>--</option> or some way that if they picked "Desktops" it would still trigger event.

Thanks
0
Comment
Question by:champ_010
2 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 125 total points
Comment Utility
Here you go:

Right after you call DataBind() on the dropdpwn list, do this (I'll use "ddl" as the name of the drop down list):

ddl.Items.Insert(0, "");

This will add that blank option to appear first in the list (the "0" is in index at which you want the item added).

John
0
 
LVL 1

Author Comment

by:champ_010
Comment Utility
Nice!  I'll be using that one alot.  Thanks John.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now