Add a new answer

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can create a new answer for an existing poll using the API:

 

[C#]

 

using CMS.Polls;

 

...

 

        string pollName = "testingSitePoll"// Poll code name

 

        // Get poll info for the specified code name

        PollInfo pollObj = PollInfoProvider.GetPollInfo(pollName);

 

        if (pollObj != null)

        {

            // Create a new answer object

            PollAnswerInfo pollAnswerObj = new PollAnswerInfo();

 

            // Set the fields

            pollAnswerObj.AnswerOrder = PollAnswerInfoProvider.GetLastAnswerOrder(pollObj.PollID) + 1;

            pollAnswerObj.AnswerCount = 0;

            pollAnswerObj.AnswerPollID = pollObj.PollID;

            pollAnswerObj.AnswerEnabled = true;

            pollAnswerObj.AnswerText = "Yes, I love it.";

 

            // Save the answer

            PollAnswerInfoProvider.SetPollAnswerInfo(pollAnswerObj);

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_add_a_new_answer.htm