I am able to get the selected value of a sitecore forms dropdown using the code below, but how can I get the selected text?
postedField.GetType().GetProperty("Value");
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communityI am able to get the selected value of a sitecore forms dropdown using the code below, but how can I get the selected text?
postedField.GetType().GetProperty("Value");
Assuming you're asking about Sitecore 9 Forms, if you have the value, you can get the selected text of a dropdown field like this:
if (field is DropDownListViewModel)
{
DropDownListViewModel dropdownField = field as DropDownListViewModel;
string selectedtext = dropdownField.Items.FirstOrDefault(a => a.Value == value)?.Text;
}
By the way, the HabitatHome demo repository has a useful little extension method sample for getting the value of a submitted form field. Check it out here