Arun
Arun

Reputation: 1472

Bind Dropdownlist using List collection

I have a country list containing the Danish name and English name of the country.I need to Bind the English name from the list to a dropdownlist.

I tried something like

ddlCountry.Items.Clear();
ddlCountry.Items.Add(new ListItem("choose", ""));
var list = Country.GetCountryList();
ddlCountry.DataSource = list;
ddlCountry.DataBind();

But the dropdown only showing sting "Country".I need to show the name of the country. My list is like below picture enter image description here

Can any one help?

Upvotes: 0

Views: 108

Answers (1)

Christos
Christos

Reputation: 53958

You could try this one:

var list = Country.GetCountryList().Select(x=>x.EnglishName);

This way using LINQ, you are selecting only the english name of the counrties that method called GetCountryList() returns.

Upvotes: 1

Related Questions