Adding “Select” option as default in Dropdown List


You can add a default “Select” option in a drop down list by two ways:

1. Before loading the drop down list with data.
2. After loading the drop down with data.

In first case you can do it as mentioned below:

DropDownList1.AppendDataBoundItems = true;
DropDownList1.Items.Add(new ListItem(“Select”, “-1”));

//Bind Your DropDownList here with data from database

For second case you can bind it as mentioned below:

//Bind Your DropDownList here with data from database
DropDownList1.Items.Insert(0, new ListItem(“Select”, “-1”));

Happy Coding 🙂

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s