Mary
Mary

Reputation:

How do I add an extra item in my drop down list,I am using datatable as datasource

I am using database table as data source for my dropdown list. How do I add an extra item in my dropdown list for example "select state".

currently my code is:

dropdownlist1.datasource=dt;
dropdownlist1.datavaluefield="countryid";
dropdownlist1.datatextfield="countryname";

dt is a datatable , "countryid" & "countryname" are columns

Upvotes: 2

Views: 1653

Answers (2)

Azhar
Azhar

Reputation: 20670

You can do it like this

dropdownlist1.DataSource = dt;
dropdownlist1.DataTextField = "countryname";
dropdownlist1.DataValueField = "countryid";
dropdownlist1.DataBind();
dropdownlist1.Items.Insert(0, new ListItem("select state", "0"));

Upvotes: 1

Singleton
Singleton

Reputation: 3679

you can do some thing like

dropdownlist1.Items.Insert(0, new ListItem("Select country", "0"));

Upvotes: 2

Related Questions