好了,现在万事俱备,只欠东风了,让我们看看现在做一个舆论调查多么简单:
file : vote.aspx
1@ Page language="c#" Codebehind="vote.cs" AutoEventWireup="false" Inherits="Football.vote"
1<html>
2<head>
3<title>532.com.cn --- 舆论调查 ---</title>
4<link href="style/style.css" rel="stylesheet" type="text/css"/>
5</head>
6<body>
7<form method="post" runat="server">
8<table align="center" height="300" width="400">
9<tr>
10<td align="center" class="cn" valign="top"><b>调查题目:
11<asp:label class="cn" id="lblSurveyTitle" runat="Server"></asp:label>
12</b></td>
13</tr>
14<tr>
15<td alin="center">
16<asp:image id="imgSurvey" runat="Server"></asp:image>
17</td>
18</tr>
19<tr>
20<td align="center">
21<input onclick="window.close();" type="button" value="关闭此窗口"/>
22</td>
23</tr>
24</table>
25</form>
26</body>
27</html>
file: vote.cs
namespace Football
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
///
1<summary>
2/// Summary description for vote.
3/// </summary>
public class vote : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image imgSurvey;
protected System.Web.UI.WebControls.Label lblSurveyTitle;
private string m_strSurveyID ;
private int m_intVoteID ;
public vote()
{
Page.Init += new System.EventHandler(Page_Init);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}
protected void Page_Init(object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP+ Windows Form Designer.
//
InitializeComponent();
Init() ;
}
///
1<summary>
2/// Required method for Designer support - do not modify
3/// the contents of this method with the code editor.
4/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler (this.Page_Load);
}
private void Init()
{
m_strSurveyID = Request["surveyid"].ToString() ;
FootballSurvey mySurvey = new FootballSurvey() ;
try
{
m_intVoteID = Request["vote"].ToInt32() ;
mySurvey.LoadFromDatabase(m_strSurveyID) ;
lblSurveyTitle.Text = mySurvey.Title ;
if (m_intVoteID < mySurvey.Items.Count)
{
mySurvey.Vote(m_intVoteID) ;
}
mySurvey.CreateResultImage(Server.MapPath("survey.jpg") ,
MyClass.Util.MyChart.ChartType.Pie ,
300 ,300 , Color.White) ;
imgSurvey.ImageUrl = "survey.jpg" ;
}
catch(Exception e)
{
#if DEBUG
Response.Write ("初始化页面错误:" + e.ToString()) ;
return ;
#endif
Page.Navigate("error.aspx") ;
}
}
}
}
要看这个调查的效果,请到http://210.12.102.95/football 。怎么样,是不是觉得这种编程思路不错呢?什么?还不如直接在aspx文件里面做?不错,如果单做这么一个调查的确直接做要省事的多,但你知不知道,只要有编译好的这个类的dll,不管你怎么改页面,改数据结构,你都可以在15分钟内把你所需要的舆论调查做出来?这就是这两种编程方法最大的区别。希望通过这个例子你能学到一些编程思想把。