Solved

Adding a List Item to the TOP of a bund DropDownList

Posted on 2004-08-18
2
255 Views
Last Modified: 2010-04-07
Ok, I have a DropDownList that is bound to a dataset:

   DropDownList1.DataSource = ds.Tables[0].DefaultView;
   DropDownList1.DataTextField = "name";
   DropDownList1.DataValueField = "category_id";
   DropDownList1.DataBind();

I would like to add a blank entry like "-- None Selected --" to the top of the list.  I tried this, but it's not what I'm looking for:
   DropDownList1.Items.Add(new ListItem("-- None Selected --",""));

If I place the above line before binding, it get blown away.  If I do it after binding, it puts it at the bottom of the list.  Is there any way to make it go to the top?

Thanks,
Daniel
0
Comment
Question by:hendridm
  • 2
2 Comments
 
LVL 20

Expert Comment

by:ihenry
ID: 11832062
How about this?

DropDownList1.Items.AddAt(new ListItem("-- None Selected --",""), 0);
0
 
LVL 20

Accepted Solution

by:
ihenry earned 200 total points
ID: 11832112
Oops..sorry, that should insert method

DropDownList1.Items.Insert(0, new ListItem("-- None Selected --",""));
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

24 Experts available now in Live!

Get 1:1 Help Now