How to get both text and value of a dropdown from Sitecore form?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am able to get the selected value of a sitecore forms dropdown using the below code. But not sure how to get selected text



postedField.GetType().GetProperty("Value");



Thanks










share|improve this question























  • Sitecore 9 Form?
    – Elena Zlateva
    8 hours ago










  • This is not SXA related question - removing SXA tag.
    – Dawid Rutkowski
    8 hours ago














up vote
1
down vote

favorite












I am able to get the selected value of a sitecore forms dropdown using the below code. But not sure how to get selected text



postedField.GetType().GetProperty("Value");



Thanks










share|improve this question























  • Sitecore 9 Form?
    – Elena Zlateva
    8 hours ago










  • This is not SXA related question - removing SXA tag.
    – Dawid Rutkowski
    8 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am able to get the selected value of a sitecore forms dropdown using the below code. But not sure how to get selected text



postedField.GetType().GetProperty("Value");



Thanks










share|improve this question















I am able to get the selected value of a sitecore forms dropdown using the below code. But not sure how to get selected text



postedField.GetType().GetProperty("Value");



Thanks







sitecore-forms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









Dawid Rutkowski

2,725221




2,725221










asked 8 hours ago









Manideep Yechuri

876




876











  • Sitecore 9 Form?
    – Elena Zlateva
    8 hours ago










  • This is not SXA related question - removing SXA tag.
    – Dawid Rutkowski
    8 hours ago
















  • Sitecore 9 Form?
    – Elena Zlateva
    8 hours ago










  • This is not SXA related question - removing SXA tag.
    – Dawid Rutkowski
    8 hours ago















Sitecore 9 Form?
– Elena Zlateva
8 hours ago




Sitecore 9 Form?
– Elena Zlateva
8 hours ago












This is not SXA related question - removing SXA tag.
– Dawid Rutkowski
8 hours ago




This is not SXA related question - removing SXA tag.
– Dawid Rutkowski
8 hours ago










1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










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






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "664"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13959%2fhow-to-get-both-text-and-value-of-a-dropdown-from-sitecore-form%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    6
    down vote



    accepted










    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






    share|improve this answer
























      up vote
      6
      down vote



      accepted










      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






      share|improve this answer






















        up vote
        6
        down vote



        accepted







        up vote
        6
        down vote



        accepted






        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 7 hours ago









        Elena Zlateva

        342210




        342210



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsitecore.stackexchange.com%2fquestions%2f13959%2fhow-to-get-both-text-and-value-of-a-dropdown-from-sitecore-form%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke