?? st_exam.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;
namespace STGROUP.ST_WebExam.ST_User
{
/// <summary>
/// ST_Exam 的摘要說明。
/// </summary>
public partial class ST_Exam : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
Response.Cache.SetCacheability(HttpCacheability.NoCache);//去掉頁面緩存
if(!IsPostBack)
{
bool flag = ST_DdlBind();
if(flag)
ST_DgBind();
}
}
/// <summary>
/// 綁定科目信息
/// </summary>
public bool ST_DdlBind()
{
ST_ExamBiz.ST_Course st_course = new STGROUP.ST_ExamBiz.ST_Course();
DataSet ds = st_course.ST_GetAllCourseInfo();
if(ds!=null && ds.Tables.Count>0 && ds.Tables[0].Rows.Count>0)
{
ddlCourse.DataSource = ds;
ddlCourse.DataBind();
return true;
}
else
{
Response.Write("<script language='javascript'>alert('請先添加科目信息!');window.location='ST_Course.aspx'</script>");
Response.End();
return false;
}
}
/// <summary>
/// 綁定問題
/// </summary>
public void ST_DgBind()
{
dgBulletin.Visible = true;
ST_ExamBiz.ST_Question st_Question = new STGROUP.ST_ExamBiz.ST_Question();
DataSet ds = st_Question.ST_GetTenQuestionInfo(int.Parse(ddlCourse.SelectedValue));
if(ds!=null && ds.Tables.Count>0 && ds.Tables[0].Rows.Count>0)
{
dgBulletin.DataSource = ds;
dgBulletin.DataBind();
}
else
{
dgBulletin.Visible = false;
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.dgBulletin.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgBulletin_ItemDataBound);
}
#endregion
protected void btnOK_Click(object sender, System.EventArgs e)
{
//根據用戶的選擇判斷如何顯示
foreach(DataGridItem dg in dgBulletin.Items)
{
RadioButtonList rblTemp = (RadioButtonList)dg.FindControl("rblAnswer");
Label lblTmp = (Label)dg.FindControl("lblRight2");
Label lblTemp = (Label)dg.FindControl("lblRight");
Label lblTemp2 = (Label)dg.FindControl("lblOK");
lblTemp.Visible = false;
lblTemp2.Visible = false;
if(rblTemp.SelectedValue != lblTmp.Text)
{
lblTemp.Visible = true;
}
else
{
lblTemp2.Visible = true;
}
}
}
protected void ddlCourse_SelectedIndexChanged(object sender, System.EventArgs e)
{
//科目變化時重新生成試題
ST_DgBind();
}
private void dgBulletin_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//根據帶有四個備選答案的RadioButtonList
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
RadioButtonList rblTemp = (RadioButtonList)e.Item.FindControl("rblAnswer");
rblTemp.Items.Add(new ListItem(drv["ST_Answer1"].ToString(),"A"));
rblTemp.Items.Add(new ListItem(drv["ST_Answer2"].ToString(),"B"));
rblTemp.Items.Add(new ListItem(drv["ST_Answer3"].ToString(),"C"));
rblTemp.Items.Add(new ListItem(drv["ST_Answer4"].ToString(),"D"));
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -