• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Adding a List Item to the TOP of a bund DropDownList

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
hendridm
Asked:
hendridm
  • 2
1 Solution
 
ihenryCommented:
How about this?

DropDownList1.Items.AddAt(new ListItem("-- None Selected --",""), 0);
0
 
ihenryCommented:
Oops..sorry, that should insert method

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now