📄 vote.aspx.cs
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
//该源码下载自www.51aspx.com(51aspx.com)
namespace vote
{
public partial class vote : System.Web.UI.Page
{
private string voteID = "1";
protected void Page_Load(object sender, 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();
}
}
protected void btnVote_Click(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update voteDetails set voteNum=voteNum+1 where voteId=" + voteID + "and voteDetailsID=" + this.rBtnItems.SelectedValue.ToString();
cmd.ExecuteNonQuery();
con.Close();
}
protected void btnShowResult_Click(object sender, EventArgs e)
{
Response.Redirect("showResult.aspx?voteid="+this.voteID);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -