⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 编写一个选举网页
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page 
{
    private string voteID = "2";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            SqlConnection con = DB.createConnect();
            con.Open();
            SqlCommand cmd = new SqlCommand("select voteTitle from voteTitle where voteID=" + this.voteID, con);
            string title = Convert.ToString(cmd.ExecuteScalar());
            this.lblTitle.Text = title;
            SqlCommand cmdItem = new SqlCommand("select * from voteDetail where voteID=" + this.voteID, con);
            SqlDataReader sdr = cmdItem.ExecuteReader();
            this.rblContent.DataSource = sdr;
            this.rblContent.DataTextField = "voteContent";
            this.rblContent.DataValueField = "voteDetailID";
            this.rblContent.DataBind();
            sdr.Close();
            con.Close();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = DB.createConnect();
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "update voteDetail set voteNum=voteNum+1 where voteID=" + this.voteID + " and voteDetailID=" + this.rblContent.SelectedValue.ToString();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    protected void btnResult_Click(object sender, EventArgs e)
    {
        Response.Redirect("showResult.aspx?voteID="+this.voteID);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -