📄 showsurvey.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Data.SqlClient;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WebApplication8.firstPage;
namespace WebApplication8.company
{
/// <summary>
/// showNews 的摘要说明。
/// </summary>
public class showSurvey : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label title;
protected System.Web.UI.HtmlControls.HtmlTableCell questionList;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
protected System.Web.UI.HtmlControls.HtmlInputButton Reset1;
protected System.Web.UI.HtmlControls.HtmlTable Table1;
protected System.Web.UI.WebControls.Label count;
private void Page_Load(object sender, System.EventArgs e)
{
string id = Request["id"];
string cmd = "select survey.title,question.question,question.a,question.b,question.c,question.id from survey join answer on answer.surveyid = survey.id join question on answer.questionid = question.id where survey.id = " + id;
Connection conn = new Connection(Application["market"].ToString());
SqlDataReader reader = conn.execute(cmd);
Table1.BorderColor = "#D0EAF9";
while(reader.Read())
{
HtmlTableRow row = new HtmlTableRow();
HtmlTableCell cell1 = new HtmlTableCell();
HtmlTableCell cell2 = new HtmlTableCell();
row.Cells.Add(cell1);
row.Cells.Add(cell2);
cell1.InnerHtml = reader["question"].ToString()+"<br>";
cell2.InnerHtml = "<SELECT size='1' name='a'>"+
"<OPTION value='a"+reader["id"].ToString()+"' selected>"+reader["a"].ToString()+"</OPTION>"+
"<OPTION value='b"+reader["id"].ToString()+"'>"+reader["b"].ToString()+"</OPTION>"+
"<OPTION value='c"+reader["id"].ToString()+"'>"+reader["c"].ToString()+"</OPTION>"+
"</SELECT>";
Table1.Rows.Add(row);
title.Text = reader["title"].ToString();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Submit1_ServerClick(object sender, System.EventArgs e)
{
try
{
Connection conn = new Connection(Application["market"].ToString());
SqlDataReader reader;
string list = Request.Form["a"];
string[] listQuestion = list.Split(",".ToCharArray());
int count = 0;
string id,choser;
while(count < listQuestion.Length)
{
choser = listQuestion[count].Substring(0,1);
id = listQuestion[count].Substring(1);
reader = conn.execute("select "+choser+" from Answer where questionid='"+id+"'");
if(reader.Read())
{
int previous = Convert.ToInt32(reader[choser]) + 1;
Response.Write(previous+" ");
reader.Close();
reader = conn.execute("update Answer set "+choser+"="+previous.ToString()+" where questionid='"+id+"'");
reader.Close();
}
count++;
}
}
catch(Exception o)
{Response.Redirect("../firstPage/index.aspx");
}
Response.Redirect("../firstPage/index.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -