ASP.NET 3.5 and above only

Poll - Save Votes - Voting Event


Favorite Movie
What is your favorite movie?
  • The Shawshank Redemption
  • The Godfather
  • Star Wars
  • Schindler's List
  • Pulp Fiction
Vote
Show Results
The Voting event may be employed to save the vote into the database.
ASP.NET
<%@ Register Assembly="Obout.Ajax.UI" Namespace="Obout.Ajax.UI.Poll" TagPrefix="obout" %>
<obout:Poll runat="server" ID="Poll1" DataSourceID="SqlDataSource1" 
     Title="Favorite Movie" Question="What is your favorite movie?"
     AllowedVotesPerUser="100" OnVoting="Poll1_Voting">
</obout:Poll>
CS
protected void Poll1_Voting(object sender, PollItemEventArgs e)
{
SqlConnection conn = new SqlConnection(connectionString);

conn.Open();

foreach (PollAnswer answer in Poll1.Answers)
{
if (answer.Selected)
{
string logVoteQuery = "UPDATE Answers SET Votes = Votes + 1 WHERE AnswerID = @AnswerID";
SqlCommand logVoteCommand = new SqlCommand(logVoteQuery, conn);
logVoteCommand.Parameters.AddWithValue("@AnswerID", answer.Item.Value);

logVoteCommand.ExecuteNonQuery();

break;
}
}

conn.Close();
}

"Thanks for the response. Your company may have the best software customer service I've ever worked with...."

Bill Jacob
The Huntington National Bank

Random testimonial   All testimonials