📄 vote.aspx.cs
字号:
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;
using System.Data .SqlClient;
namespace vote
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnVote;
protected System.Web.UI.WebControls.Button btnResult;
protected System.Web.UI.WebControls.Label lblTitle;
protected System.Web.UI.WebControls.RadioButtonList rBtnItems;
private String voteID="2";
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{//建立连接
SqlConnection con=DB.createConnection();
con.Open();
//查询项目标题
SqlCommand cmd=new SqlCommand("select voteTitle from voteMaster where voteID="+this.voteID,con);
String title=Convert.ToString(cmd.ExecuteScalar());
this.lblTitle.Text =title;
//查询相应的投票条目
SqlCommand cmdItem=new SqlCommand("select voteDetailsID,voteItem from voteDetails where voteID="+this.voteID,con);
SqlDataReader sdr=cmdItem.ExecuteReader();
this.rBtnItems.DataSource=sdr;
this.rBtnItems.DataTextField="voteItem";
this.rBtnItems.DataValueField="voteDetailsID";
this.rBtnItems.DataBind();
sdr.Close();
con.Close();
}
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnVote.Click += new System.EventHandler(this.btnVote_Click);
this.btnResult.Click += new System.EventHandler(this.btnResult_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void rBtnItems_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void btnVote_Click(object sender, System.EventArgs e)
{
SqlConnection con=DB.createConnection();
con.Open();
SqlCommand cmd=new SqlCommand ("update voteDetails set voteNum=voteNum+1 where voteID="+voteID+"and voteDetailsID="+this.rBtnItems.SelectedValue.ToString(),con);
cmd.ExecuteNonQuery();
con.Close();
}
private void btnResult_Click(object sender, System.EventArgs e)
{
SqlConnection con=DB.createConnection();
con.Open();
SqlCommand cmd=new SqlCommand("select * from voteDetails where voteID="+voteID,con);
SqlDataReader sdr=cmd.ExecuteReader();
while(sdr.Read ())
{
Response.Write("<font size=15>"+sdr.GetString(2)+"-----"+sdr.GetInt32(3).ToString()+"</font><br>");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -