WebPoll in C#[Vs.net Bate2 等级:中 高]
2024-07-10 12:58:16
供稿:网友
webpoll in c# is implemented as a user control in a vs.net beta2 project. the database behind the control is sql server, but it could easily be moved to access. i needed a webpoll for my site, saw one done on asptoday in vbscript for regular asp. i made a few modifications and converted the project to .net and c#. a working copy of the webpoll can be viewed at http://72t.net (what i really do in life) or at http://dn.yyyz.net (the initial conversion of my personal site).
as you play, please send me any changes and suggestions for improving the code - i'm still learning both .net and c#. if you implement the poll on your site, you should probably use at least two answers to each question - a one question poll doesn't make much sense. the number of answers isn't limited - enter as many as you like. using different poll ids, you can have multiple polls running on the same site at the same time.
things to look for in the code:
construction of a table with rows and cells in the c# code behind page.
adding radio buttons and text to individual table cells.
implementing a submit button and handler from the code behind page.
stepping through a group of radio buttons to query for the checked button.
use of cookies to overcome multiple answers from the same computer.
use of classes for both the question and answers
main files:
default.aspx - a page used to implement the control. the control is registered. two items, the poll id and the connection string are passed to the webpoll control
webpoll.ascx - the html portion of the control. this page only has a placeholder control that is used as a place holder. all the code (tables, etc.) are constructed in the code behind class.
webpoll.ascx.cs - the code behind class - the control is built entirely in the .cs code behind page. look through the actual page for comments and explanation. it builds two tables, one to ask the questions and one to show the results.
webpoll.sql - the sql query file (created by sql 2000) that will create the tables used by the webpoll control - questions go in 'pollquestions' table and the answers go in the 'pollanswers '.
webpoll.htm - this page
possible improvements (if you make any, please let me know) :
a user interface that could be used to add or delete questions - in this version, you have to enter the items into the database tables manually.
a button that would allow viewing the results of previous polls.
converting the existing usercontrol to a full web control.
source code