?
Solved

<asp:DropDownList>  OnSelectedIndexChanged

Posted on 2004-09-01
2
Medium Priority
?
281 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 500 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 August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free 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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

801 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