日期:2014-05-18 浏览次数:21118 次
HttpCookie littcookie = new HttpCookie("littxt"); //littcookie.Expires = DateTime.Now.AddDays(1);//我这里设置的是过期时间为一天,你可以自己改 try { lblEndtime.Text = "本次题目共10道,每小题1分!"; lblStuNum.Text = Session["danwei"].ToString();//所在单位 lblStuName.Text = Session["name"].ToString(); lblStuSex.Text = Session["sex"].ToString(); lblStuKM.Text = "[" + Session["KM"].ToString() + "]" + "考试试题"; int i = 1; int num = 1; int bie = 0; SqlConnection conn = BaseClass.DBCon(); conn.Open(); SqlCommand cmd = new SqlCommand("select top 10 * from tb_test where testCourse='" + Session["KM"].ToString() + "' order by newid()", conn); // 指定两个题目必须出现 select * from (SELECT top 2 *,NewId() As RandromX FROM tb_test Where id < 3 and testCourse='初级' Order By RandromX) A //UNION ALL //select * from (SELECT top 8 *,NewId() As RandromX FROM tb_test Where id > 3 and testCourse='初级' Order By RandromX) B SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { Literal littxt = new Literal(); Literal litti = new Literal(); CheckBoxList che = new CheckBoxList();//复选框多选择 RadioButtonList cbk = new RadioButtonList(); cbk.ID = "cbk" + i.ToString(); littxt.Text = "<input type='hidden' name='db_" + bie.ToString() + "' id='db_" + bie.ToString() + "' value='' answer='" + Server.HtmlEncode(sdr["rightAns"].ToString()) + "'/>" + "<div class='result' id='result_" + bie.ToString() + "' >" + i.ToString() + "、" + Server.HtmlEncode(sdr["testContent"].ToString()); litti.Text = "</div>"; littcookie["littxt"] += HttpUtility.UrlEncode(littxt.Text + "|"); littcookie["acbk"] += HttpUtility.UrlEncode(sdr["testAns1"].ToString()) + "|"; littcookie["bcbk"] += HttpUtility.UrlEncode(sdr["testAns2"].ToString()) + "|"; littcookie["ccbk"] += HttpUtility.UrlEncode(sdr["testAns3"].ToString()) + "|"; littcookie["dcbk"] += HttpUtility.UrlEncode(sdr["testAns4"].ToString()) + "|"; cbk.Items.Add("A. " + Server.HtmlEncode(sdr["testAns1"].ToString())); cbk.Items.Add("B. " + Server.HtmlEncode(sdr["testAns2"].ToString())); cbk.Items.Add("C. " + Server.HtmlEncode(sdr["testAns3"].ToString())); cbk.Items.Add("D. " + Server.HtmlEncode(sdr["testAns4"].ToString())); cbk.Font.Size = 11; for (int j = 1; j <= 4; j++) { cbk.Items[j - 1].Value = j.ToString(); //cbk.Attributes["onclick"] = " db(1, "+i.ToString()+")"; cbk.Items[j - 1].Attributes.Add("onclick", " db(" + bie.ToString() + ", " + num++ + ")");//给input标签加事件 } num = 1; bie++; Ans += sdr[6].ToString(); if (Session["a"] == null) { Session["Ans"] = Ans