一、单项选择题(共10题,每题2分) |
'>--%>
| --%>
|
|
|
|
二、判断题(共10题,每题2分) |
'>--%>
| --%>
|
|
这是前台的代码,下面的是后台的代码
int score = 0;
//int singlemark = int.Parse(((Label)GridView1.Rows[0].FindControl("Label4")).Text);//取出单选题的每题分值
foreach (RepeaterItem rs in Repeater1.Items)//对单选题每题进行判断用户选择答案
{
string ta = Request.QueryString["tabName"];
string str = "";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=localhost;Initial Catalog=zh;Integrated Security=True";
// 打开连接
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
if (((RadioButton)rs.FindControl("RadioButton1")).Checked)
{
str = "A";
string aa = ((Label)rs.FindControl("Label1")).Text.Trim();
string mysql1 = "update "+ ta +" set col8='A' where col1="+aa;
SqlCommand cmd1 = new SqlCommand(mysql1, conn);
cmd1.ExecuteNonQuery();
}
else if (((RadioButton)rs.FindControl("RadioButton2")).Checked)
{
str = "B";
string aa = ((Label)rs.FindControl("Label1")).Text.Trim();
string mysql1 = "update " + ta + " set col8='B' where col1=" + aa;
SqlCommand cmd1 = new SqlCommand(mysql1, conn);
cmd1.ExecuteNonQuery();
}
else if (((RadioButton)rs.FindControl("RadioButton3")).Checked)
{
str = "C";
string aa = ((Label)rs.FindControl("Label1")).Text.Trim();
string mysql1 = "update " + ta + " set col8='C' where col1=" + aa;
SqlCommand cmd1 = new SqlCommand(mysql1, conn);
cmd1.ExecuteNonQuery();
}
else if (((RadioButton)rs.FindControl("RadioButton4")).Checked)
{
str = "D";
string aa = ((Label)rs.FindControl("Label1")).Text.Trim();
string mysql1 = "update " + ta + " set col8='D' where col1=" + aa;
SqlCommand cmd1 = new SqlCommand(mysql1, conn);
cmd1.ExecuteNonQuery();
}
if (((Label)rs.FindControl("Label3")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score = score + 2;
}
}
foreach (RepeaterItem dr in Repeater2.Items)//对判断题每题进行判断用户选择答案
{
string str = "";
if (((RadioButton)dr.FindControl("RadioButton11")).Checked)
{
str = "A";
}
else if (((RadioButton)dr.FindControl("RadioButton12")).Checked)
{
str = "B";
}
if (((Label)dr.FindControl("Label13")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score = score + 2;
}
Response.Write(score);
}
我的repeater2的foreach不执行,求助大神,这是为什么