Solved

Adding a List Item to the TOP of a bund DropDownList

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 36
ASP.net Fit 3 divs on screen side by side 3 27
How to close an asp.net web form using C# ? 4 31
imap mails 1 23
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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