Loading ...

How to add first option in dropdownlist

Who is online?  0 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

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

Posted: 10/27/2009

Lurker 170  points  Lurker
  • Joined on: 10/17/2009
  • 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



tags c#

Posted: 10/27/2009

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483
  Answered

Posted: 10/27/2009

Professional 8088  points  Professional
  • Joined on: 4/15/2009
  • Posts: 422
  Answered

Here another article that you can refer:

Adding Default Select Option in the DroDownList


Posted: 10/28/2009

Contributor 2841  points  Contributor
  • Joined on: 11/29/2008
  • Posts: 62
  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


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