Click here to Skip to main content
11,802,442 members (69,788 online)
Click here to Skip to main content

Survey/Polling System Using RadioButton List

, 9 May 2012 CPOL 12.5K 1.6K 4
Rate this:
Please Sign up or sign in to vote.
An article to demonstrate a polling/survey system in ASP.NET using a RadioButtonList.




Here I show a simple way to develop a polling/survey system like that in CodeProject. It shows the results with percentage of votes in a graphical manner. I have used a RadioButtonList to show poll options to select an option.

Database Diagram

I have three tables: one for question, second for offered answers, and third to store the answers selected by users.

Insert Poll and Options

Here is the Stored Procedure for inserting a poll and various options/answers:

CREATE PROCEDURE [dbo].[insQues]
    @ques varchar(350),
    @other varchar(250)
    update tblQues set status=0;
    insert into tblQues (qText,other) values(@ques,@other);

CREATE PROCEDURE [dbo].[insAnswers]
    @anstext varchar(450)
    declare @qid int
    select @qid=MAX(qid) from tblQues;
    insert into tblQuesAns (qID,anstext) values(@qid,@anstext);

Here I input options/answers in one text box and split it by ';' to separate various options.

SqlCommand cmdins = ff.getCommand("insQues");
cmdins.Parameters.AddWithValue("@ques", txtQues.Text);
cmdins.Parameters.AddWithValue("@other", txtOther.Text);
//we have to insert each answer so split it by ; to seperate answer
 String[] ans = txtAns.Text.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

foreach (string ss in ans)
    cmdins = ff.getCommand("insAnswers");
    cmdins.Parameters.AddWithValue("@anstext", ss);

Showing Graphical Results

To show results graphically for quick analysis, I have used a StringBuilder and calculate the percentage as Number of votes of respective answers*100/total no of votes.

And now I set an image within the td and the width of this image is this percentage. See Image-2.

Point of Interest

Here I want to fetch the answers and the total number of answers count from the tblQuesAns table. So I use an output parameter.

CREATE PROC [dbo].[selectResults]
    @qid int,
    @b int output
select anstext,anscount from tblQuesAns where qID=@qid;
set @b=(select sum(anscount) from tblQuesAns where qID=@qid);


Now, how to fetch the value of @b in C#:

SqlCommand cmd = ff.getCommand("selectResults");
SqlParameter sp = cmd.Parameters.Add("@b", SqlDbType.Int);
sp.Direction = ParameterDirection.Output;
int total =int.Parse(cmd.Parameters["@b"].Value.ToString());
SqlDataReader dr = cmd.ExecuteReader();

Future Scope

This has the limitation to select only one option. So I will modify this with a RadioButtonList and CheckBoxList both, and change this to a custom control to make it more useful. Thank you for reading.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
India India

A technology enthusiast and software developer by profession. He is developing .Net/database based enterprise applications from past 4 years.

His skills includes C# ,ASP.NET, ASP.NET MVC,WCF,JQuery,Javascript,SQL Server,Oracle . His areas of interests are database development and application software development using Microsoft Technologies.

Visit his blog:

Blog | Articles | Answers |Facebook
The best anti-virus is a smart user

You may also be interested in...

Comments and Discussions

Questionnice job Pin
eenoogsa9-May-12 18:42
membereenoogsa9-May-12 18:42 
AnswerRe: nice job Pin
Uma Shankar Patel9-May-12 18:44
memberUma Shankar Patel9-May-12 18:44 
thanks for appreciation.......

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151002.1 | Last Updated 9 May 2012
Article Copyright 2012 by uspatel
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid