?
Solved

Adding a List Item to the TOP of a bund DropDownList

Posted on 2004-08-18
2
Medium Priority
?
268 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 800 total points
ID: 11832112
Oops..sorry, that should insert method

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 1 hour left to enroll

777 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