Who is online?  209 guests and 0 members
home »forums »basic asp.net »web forms »How to add first option in dropdownlist

How to add first option in dropdownlist

Topic RSS Feed

Posts under the topic: How to add first option in dropdownlist

Posted: 10/27/2009 12:06:24 PM

Lurker 170  points  Lurker
  • Joined on: 10/17/2009 1:28:08 AM
  • Posts: 34

Hi,

 

How to add first option in dropdownlist after i have bind my dropdownlist with my datasource. ie

i have below code

 

Dropdownlist1.DataSource= mysource;

Dropdownlist1.Databind();

 

I want to insert an item with text "Please Select" and value=0



c#

Posted: 10/27/2009 12:38:03 PM

Professional 10133  points  Professional
  • Joined on: 4/19/2009 1:46:52 AM
  • Posts: 241
answered  Answered
c#, dropdownlist

Posted: 10/27/2009 9:06:47 PM

Contributor 5776  points  Contributor
  • Joined on: 4/15/2009 12:12:23 PM
  • Posts: 267
answered  Answered

Here another article that you can refer:

Adding Default Select Option in the DroDownList


Posted: 10/28/2009 12:47:46 AM

Contributor 2656  points  Contributor
  • Joined on: 11/29/2008 6:26:22 AM
  • Posts: 55
answered  Answered

 

shawn said:

I want to insert an item with text "Please Select" and value=0



Hi Shawn,
             You can insert text in dropdownlist in following two ways:

         Dropdownlist1.Items.Insert(0, new ListItem("Please Select User Name", "0"));
         Dropdownlist1.Items.Add(new ListItem("Please Select User Name", "0"));


For more information for Insert and Add an item in DropDownlist follow following link:
http://www.codeasp.net/blogs/Vijjendra/microsoft-net/59/insertadd-a-listitem-to-a-dropdownlist


C#, asp.net
Page 1 of 1 (4 items)