Solved

Adding a List Item to the TOP of a bund DropDownList

Posted on 2004-08-18
2
266 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
[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
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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