问题描述
由于字数的问题我只写了单选题if(!IsPostBack){if(Session["power"]==null){Response.Write("<script>alert("对不起,您还未登录!");</script>");Response.Write("<script>window.location.href='announcement.aspx';</script>");return;}if(Request.QueryString["ID"]==null){Response.Redirect("announcement.aspx");return;}Session["mainsrc"]=Request.Url.ToString();}if(Session["exam"]==null){if(!readQuestions())return;}createPaper();}protectedvoidButton1_Click(objectsender,EventArgse){if(Session["exam"]==null){ClientScript.RegisterStartupScript(this.GetType(),"error","<script>alert("当前会话已超时,请重新登录考试!");</script>");return;}DataSetds=(DataSet)Session["exam"];intscore=0;for(inti=0;i<ds.Tables["questions"].Rows.Count;i++){if(ds.Tables["questions"].Rows[i]["题型"].ToString()=="单选题"){if(ds.Tables["questions"].Rows[i]["答案"].ToString()==((RadioButtonList)table1.FindControl(ds.Tables["questions"].Rows[i]["ID"].ToString())).SelectedValue)score+=Convert.ToInt32(ds.Tables["exam"].Rows[0]["单选分"]);}if(ds.Tables["questions"].Rows[i]["题型"].ToString()=="多选题"){boolflag=false;stringtemp="";for(intj=0;j<((CheckBoxList)table1.FindControl(ds.Tables["questions"].Rows[i]["ID"].ToString())).Items.Count;j++){if(((CheckBoxList)table1.FindControl(ds.Tables["questions"].Rows[i]["ID"].ToString())).Items[j].Selected){if(flag)temp+=","+((CheckBoxList)table1.FindControl(ds.Tables["questions"].Rows[i]["ID"].ToString())).Items[j].Value;else{flag=true;temp+=((CheckBoxList)table1.FindControl(ds.Tables["questions"].Rows[i]["ID"].ToString())).Items[j].Value;}}}if(temp==ds.Tables["questions"].Rows[i]["答案"].ToString())score+=Convert.ToInt32(ds.Tables["exam"].Rows[0]["多选分"]);}}stringsqlStr="";if(ds.Tables["exam"].Rows[0]["考试科目"].ToString()=="英语考试".ToString())sqlStr="insertintofxq_examvalues("+ds.Tables["exam"].Rows[0]["ID"].ToString()+","+Session["ID"].ToString()+","+score.ToString()+")";elseif(ds.Tables["exam"].Rows[0]["考试科目"].ToString()=="数学考试")sqlStr="insertintohl_examvalues("+ds.Tables["exam"].Rows[0]["ID"].ToString()+","+Session["ID"].ToString()+","+score.ToString()+")";elsesqlStr="insertintofg_examvalues("+ds.Tables["exam"].Rows[0]["ID"].ToString()+","+Session["ID"].ToString()+","+score.ToString()+")";SqlCommandcmd=newSqlCommand(sqlStr,conn);try{conn.Open();cmd.ExecuteNonQuery();conn.Close();}catch(Exceptionex){ClientScript.RegisterStartupScript(this.GetType(),"error","<script>alert("SORRY,录入考试成绩时出错!");</script>");return;}finally{conn.Close();}Session["exam"]=null;Response.Redirect("oneself_fraction.aspx");}protectedboolreadQuestions(){DataSetds=newDataSet();stringsqlStr="select*fromexam_tbwhereID="+Request.QueryString["ID"].ToString();SqlDataAdapterad=newSqlDataAdapter(sqlStr,conn);try{conn.Open();ad.Fill(ds,"exam");conn.Close();}catch(Exceptionex){ClientScript.RegisterStartupScript(this.GetType(),"error","<script>alert("读取考试信息出错!");</script>");returnfalse;}finally{conn.Close();}if(ds.Tables["exam"].Rows[0]["考试科目"].ToString()=="英语考试")sqlStr="select*fromfxq_examwhere考试号="+Request.QueryString["ID"].ToString()+"and证件号码="+Session["ID"].ToString();elseif(ds.Tables["exam"].Rows[0]["考试科目"].ToString()=="数学考试")sqlStr="select*fromhl_examwhere考试号="+Request.QueryString["ID"].ToString()+"and证件号码="+Session["ID"].ToString();elsesqlStr="select*fromfg_examwhere考试号="+Request.QueryString["ID"].ToString()+"and证件号码="+Session["ID"].ToString();SqlCommandcmd=newSqlCommand(sqlStr,conn);try{conn.Open();SqlDataReaderread=cmd.ExecuteReader();if(read.Read()){conn.Close();ClientScript.RegisterStartupScript(this.GetType(),"error","<script>alert("您已进行过考试!");document.location.href='announcement.aspx';</script>");returnfalse;}conn.Close();}catch(Exceptionex){ClientScript.RegisterStartupScript(this.GetType(),"error","<script>alert("读取考试信息出错!");</script>");returnfalse;}finally{conn.Close();}Label1.Text=ds.Tables["exam"].Rows[0]["ID"].ToString();Label2.Text=ds.Tables["exam"].Rows[0]["考试科目"].ToString();Label3.Text=ds.Tables["exam"].Rows[0]["考试名称"].ToString();Label4.Text=Session["ID"].ToString();Label5.Text=Session["uname"].ToString();Label6.Text=(Convert.ToInt32(ds.Tables["exam"].Rows[0]["时间"])*60).ToString();if(Convert.ToInt32(ds.Tables["exam"].Rows[0]["单选"])>0){sqlStr="selecttop"+ds.Tables["exam"].Rows[0]["单选"]+"*fromquestions_tbwhere题型='单选题'orderbynewid()";ad=newSqlDataAdapter(sqlStr,conn);try{conn.Open();ad.Fill(ds,"questions");conn.Close();}catch(Exceptionex){ClientScript.RegisterStartupScript(this.GetType(),"error","<script>alert("读取题库出错!");</script>");returnfalse;}finally{conn.Close();}}Session["exam"]=ds;returntrue;}protectedvoidcreatePaper()//开始生成试卷页面{DataSetds=(DataSet)Session["exam"];DataRow[]single=ds.Tables["questions"].Select("题型='单选题'");HtmlTableRowtitle;HtmlTableCellcell;if(single.Length>0){cell=newHtmlTableCell();title=newHtmlTableRow();cell.ColSpan=2;cell.Style.Add("font-weight","bold");cell.Style.Add("text-align","left");cell.InnerHtml="单选题(共"+single.Length+"题,每题"+ds.Tables["exam"].Rows[0]["单选分"].ToString()+"分)";title.Cells.Add(cell);table1.Rows.Add(title);for(inti=0;i<single.Length;i++){HtmlTableRowrow1=newHtmlTableRow();HtmlTableCellcell1=newHtmlTableCell();cell1.Style.Add("width","30px");cell1.Style.Add("text-align","center");cell1.InnerHtml=(i+1).ToString();HtmlTableCellcell2=newHtmlTableCell();cell2.Style.Add("text-align","left");cell2.InnerHtml=single[i]["题目"].ToString();row1.Cells.Add(cell1);row1.Cells.Add(cell2);HtmlTableRowrow2=newHtmlTableRow();HtmlTableCellcell3=newHtmlTableCell();cell3.Style.Add("width","30px");cell3.InnerHtml=" ";HtmlTableCellcell4=newHtmlTableCell();cell4.Style.Add("text-align","left");RadioButtonListlist=newRadioButtonList();list.ID=single[i]["ID"].ToString();list.Width=Unit.Pixel(550);ListIteml1=newListItem("A."+single[i]["A"].ToString(),"A");ListIteml2=newListItem("B."+single[i]["B"].ToString(),"B");ListIteml3=newListItem("C."+single[i]["C"].ToString(),"C");ListIteml4=newListItem("D."+single[i]["D"].ToString(),"D");list.Items.Add(l1);list.Items.Add(l2);list.Items.Add(l3);list.Items.Add(l4);cell4.Controls.Add(list);row2.Cells.Add(cell3);row2.Cells.Add(cell4);table1.Rows.Add(row1);table1.Rows.Add(row2);}}}}}
解决方案
解决方案二:
不看你的代码,大概思路就是放个隐藏的Label之类的,有错误就把Label显示,Label存放正确答案。
解决方案三:
同意楼上说的。把正确答案放到一个Label里面,这个Label是处于隐藏的状态,当用户回答完问题点提交之后,就判断用户选择的答案与正确答案是否一致。如果一致的话加载下一题的内容,并把下一题的正确答案放到Label里面。如果答案不正确的话就提示错误,再把label显示出来。用户点击下一题之后再把label隐藏,然后加载下一题的内容。
解决方案四:
用不用保存试卷啊?隐藏label怎么着?
解决方案五:
隐蔽label怎么写啊?
解决方案六:
label.visiable=false;
解决方案七:
label就可以完全搞定了,很简单的。