📄 examine.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 ExamineSystem
{
/// <summary>
/// Summary description for Examine.
/// </summary>
public class Examine : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList QuestionList;
protected System.Web.UI.WebControls.DataGrid KindList;
protected System.Web.UI.HtmlControls.HtmlGenericControl title;
protected System.Web.UI.WebControls.Button ResultExamine;
private int nKindID = 0;
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.Params["KindID"] != null)
{
nKindID = Int32.Parse(Request.Params["KindID"].ToString());
}
if(!Page.IsPostBack)
{
///绑定试题种类数据
BindQuestionKindData();
///绑定试题的数据
if(nKindID > 0)
{
BindQuestionDataByKind(nKindID);
}
else
{
BindQuestionData();
}
}
}
private void BindQuestionKindData()
{
QuestionDB question = new QuestionDB();
SqlDataReader recq = question.GetQuestionKinds();
KindList.DataSource = recq;
KindList.DataBind();
recq.Close();
}
private void BindQuestionDataByKind(int nKindID)
{
ArrayList QuestionIDList = new ArrayList();
if(Session[Session.SessionID + Session["UserName"].ToString()] != null)
{
QuestionIDList = (ArrayList)Session[Session.SessionID + Session["UserName"].ToString()];
}
QuestionDB question = new QuestionDB();
IList questionList = (IList)question.GetQuestions(QuestionIDList,nKindID);
QuestionList.DataSource = questionList;
QuestionList.DataKeyField = "QuestionID";
QuestionList.DataBind();
}
private void BindQuestionData()
{
ArrayList QuestionIDList = new ArrayList();
if(Session[Session.SessionID + Session["UserName"].ToString()] != null)
{
QuestionIDList = (ArrayList)Session[Session.SessionID + Session["UserName"].ToString()];
}
QuestionDB question = new QuestionDB();
IList questionList = (IList)question.GetQuestions(QuestionIDList);
QuestionList.DataSource = questionList;
QuestionList.DataKeyField = "QuestionID";
QuestionList.DataBind();
}
private void BindAnswerList(RadioButtonList radioList,int nQuestionID)
{
AnswerDB answer = new AnswerDB();
SqlDataReader reca = answer.GetAnswers(nQuestionID);
radioList.DataSource = reca;
radioList.DataTextField = "Body";
radioList.DataValueField = "AnswerID";
radioList.DataBind();
reca.Close();
if(radioList.Items.Count > 0)
{
radioList.SelectedIndex = 0;
radioList.SelectedItem.Attributes.Add("ForeColor","Red");
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.QuestionList.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(this.QuestionList_ItemDataBound);
this.QuestionList.SelectedIndexChanged += new System.EventHandler(this.QuestionList_SelectedIndexChanged);
this.ResultExamine.Click += new System.EventHandler(this.ResultExamine_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void QuestionList_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
RadioButtonList answerList = (RadioButtonList)e.Item.FindControl("AnswerList");
if(answerList != null)
{
BindAnswerList(answerList,Int32.Parse(QuestionList.DataKeys[e.Item.ItemIndex].ToString()));
}
}
private void ResultExamine_Click(object sender, System.EventArgs e)
{
Response.Redirect("~/GetScore.aspx");
}
private void QuestionList_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -