当前位置:编程学习 > C#/ASP.NET >>

WebPoll in C#Vs.net Bate2 等级:中 高

答案: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

上一个:asp.net key considerations(二)
下一个:Form code generator V1.1 by Steve Schofieldbate2 等级:中级(转载:aspfree)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,