1

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 9 Form? – Elena Zlateva Sep 18 '18 at 19:58
  • This is not SXA related question - removing SXA tag. – Dawid Rutkowski Sep 18 '18 at 20:05
9

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.