Solved

<asp:DropDownList>  OnSelectedIndexChanged

Posted on 2004-09-01
2
276 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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