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");
2
  • Sitecore 9 Form? Sep 18, 2018 at 19:58
  • This is not SXA related question - removing SXA tag. Sep 18, 2018 at 20:05

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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