skmagic 2016-06-05 14:58 采纳率: 0%
浏览 1245

求大神帮忙看一下这是什么问题

--%>
一、单项选择题(共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不执行,求助大神,这是为什么
  • 写回答

1条回答

  • threenewbee 2016-06-05 14:59
    关注

    Repeater2.Items是否为空,下一个断点调试下。

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示