日期:2014-05-17 浏览次数:20468 次
public string ReaderQuestion(string type) { //所有题目 DataTable ddt = (DataTable)ViewState["question"]; //获取选择的答案 string answer = Request.Form["answer"]; //获取题目序号 int num = Convert.ToInt32(hidNum.Text); int sum = Convert.ToInt32(HidSum.Text); //给上一题的答案赋值 if (num - 1 >= 0) { ddt.Rows[num - 1]["Answer"] = answer; } if (type == "up") { if (num <= sum && num > 0) { num = num - 1; } } else if (type == "next") { if (num < sum) { num = num + 1; } } hidNum.Text = num.ToString(); ; //查询当前序号的题目信息 DataRow[] drs = ddt.Select(string.Format("QuestionNum={0}", num)); if (drs.Length > 0) { DataRow dr = drs[0]; StringBuilder sb = new StringBuilder(); sb.Append("<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" class=\"intable\"><tr><td class=\"borr\" colspan=\"4\"><div>"); sb.Append(num + "." + dr["Title"]); sb.Append("</div></td></tr><tr>"); string QuestionType = dr["QuestionType"].ToString().Trim(); //判断题目类型生成不同的HTML if ("多选".Trim().Equals(QuestionType)) { string[] selectAn = dr["SelectAn"].ToString().Split('|'); for (int i = 0; i < selectAn.Length; i++) { sb.Append("<td class=\"bor\"><input id=\"input_" + i + "\" type=\"checkbox\" name=\"answer\" value=" + selectAn[i] + "/>" + selectAn[i] + "</td>"); } } else if ("单选".Trim().Equals(QuestionType)) { string[] selectAn = dr["SelectAn"].ToString().Split('|'); for (int i = 0; i < selectAn.Length; i++) { sb.Append("<td class=\"bor\"><input id=\"input_" + i + "\" type=\"radio\" name=\"answer\" value=" + selectAn[i] + " />" + selectAn[i] + "</td>"); } } else if ("更多题型".Trim().Equals(QuestionType)) { } sb.Append("</tr></table>"); ViewState["question"] = ddt; //将最新的数据保存到viewstate中 return sb.ToString(); } else { return "已经没有题目了!"; } }