Change the number of votes

  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 increase the number of votes for a given answer using the API. It's useful if you want to create your own voting dialog.

 

[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)

        {

            // Get all answers of the poll

            DataSet ds = PollAnswerInfoProvider.GetAnswers(pollObj.PollID);

 

            if (!DataHelper.DataSourceIsEmpty(ds))

            {

                // Get first pollanswerinfo object

                PollAnswerInfo pollAnswerObj = new PollAnswerInfo(ds.Tables[0].Rows[0]);

 

                if (pollAnswerObj != null)

                {

                    // Increment votes by 1

                    pollAnswerObj.AnswerCount++;

 

                    // Save the data

                    PollAnswerInfoProvider.SetPollAnswerInfo(pollAnswerObj);

                }

             }

          }

 

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