Hi,
Can someone tell me if there is an easier way too bind an collection to a dropdownlist instead of:
CountryCollection countryCollection = CountryManager.GetAllCountries();
ddlCountries.Items.Add(new ListItem("",""));
if (countryCollection.Count >0)
{
foreach (CountryEntity countryEntity in countryCollection)
{
ListItem listItem = new ListItem(countryEntity.Name, countryEntity.CountryId.ToString());
ddlCountries.Items.Add(listItem);
}
}
I was thinking something like:
CountryCollection countryCollection = CountryManager.GetAllCountries();
ddlCountries.DataSource = countryCollection;
ddlCountries.DataValueField = "ID";
ddlCountries.DataTextField = "Name";
ddlCountries.DataBind();
but this does nog work.....