Solved

<asp:DropDownList>  OnSelectedIndexChanged

Posted on 2004-09-01
2
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
jnhorst earned 125 total points
ID: 11959187
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
ID: 11959262
Nice!  I'll be using that one alot.  Thanks John.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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