I want to set DataTextField
and DataValueField
of a Dropdownlist
(languageList) using a Dictionary (list) of languageCod
(en-gb) as key and language name (english) as the text to display.
Relevant Code:
string[] languageCodsList= service.LanguagesAvailable();
Dictionary<string, string> list =
new Dictionary<string, string>(languageCodsList.Length);
foreach (string cod in languageCodsList)
{
CultureInfo cul = new CultureInfo(cod);
list.Add(cod, cul.DisplayName);
}
languageList.DataSource = list;
languageList.DataBind();
How can I set DataTextField
and DataValueField
?
Best Solution
Like that you can set DataTextField and DataValueField of DropDownList using "Key" and "Value" texts :