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?

  • Sitecore 9 Form? Sep 18 '18 at 19:58
  • This is not SXA related question - removing SXA tag. Sep 18 '18 at 20:05

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, privacy policy and cookie policy

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