📄 pretest.aspx.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
{
protected SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TestLibraryConnectionString"].ConnectionString);
if (IsPostBack)
return;
DataTable table1 = new DataTable();
try
{
conn.Open();
SqlCommand cmd1 = new SqlCommand("GetTestInfo", conn);
cmd1.CommandType = CommandType.StoredProcedure;
table1.Load(cmd1.ExecuteReader());
if (table1.Rows.Count == 0) //无现有测试
{
Button1.Enabled = false;
}
else
{
RadioButtonList1.DataSource = table1;
RadioButtonList1.DataValueField = "ID";
RadioButtonList1.DataTextField = "Information";
RadioButtonList1.DataBind();
RadioButtonList1.SelectedIndex = 0;
}
}
catch (Exception exp)
{
Response.Write("错误:无法建立数据连接:" + exp.Message);
}
finally
{
if (conn != null && conn.State != ConnectionState.Closed)
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
conn.Open();
SqlCommand cmd1 = new SqlCommand("GetTest", conn);
cmd1.CommandType = CommandType.StoredProcedure;
SqlParameter par1 = new SqlParameter("@testID", SqlDbType.Int);
par1.Value = RadioButtonList1.SelectedValue;
cmd1.Parameters.Add(par1);
DataTable table1 = new DataTable();
table1.Load(cmd1.ExecuteReader());
Session["Questions"] = table1;
Session["TestID"] = RadioButtonList1.SelectedValue;
Session["TesteeNumber"] = TextBox1.Text;
Response.Redirect("Test.aspx?no=1");
}
catch (Exception exp)
{
Response.Write("数据访问错误:" + exp.Message);
}
finally
{
if (conn != null && conn.State != ConnectionState.Closed)
conn.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -