我正在尝试从用户那里获得所有检查值,但我没有这样做
参考下面的//问题,当选中checkboxlist项时,它应该返回给我用户选择的内容,但它无法检测用户已检查的内容
绑定转发器项目
if (Session["test"] != null)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmdLoadQuestion = new SqlCommand("getTestQuestion",conn);
conn.Open();
cmdLoadQuestion.Parameters.Add("@subject",SqlDbType.VarChar).Value=Session["test"].ToString();
cmdLoadQuestion.CommandType = CommandType.StoredProcedure;
SqlDataReader dtrLoadQuestion;
dtrLoadQuestion = cmdLoadQuestion.ExecuteReader();
Repeater1.DataSource = dtrLoadQuestion;
Repeater1.DataBind();
dtrLoadQuestion.Close();
conn.Close();
}
else
{
Response.Redirect("~/HomePage.aspx");
}
//check answer from db
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
foreach (RepeaterItem items in Repeater1.Items)
{
SqlCommand cmdCheckAnswer = new SqlCommand("Select Answer From ExerciseTable where Question='" + ((Label)items.FindControl("Label3")).Text + "'", conn);
SqlDataReader dtrCheckAnswer;
dtrCheckAnswer = cmdCheckAnswer.ExecuteReader();
if (dtrCheckAnswer.Read())
{
CheckBoxList chkList = (CheckBoxList)items.FindControl("chkOption");
foreach (ListItem a in chkList.Items)
{
//Problem
if (a.Selected == true)
{
marks.InnerHtml += dtrCheckAnswer["Answer"].ToString() + " user Answer:" + a.Text + "<br/>";
}
else
{
marks.InnerHtml += "u check nth at all";
}
}
}
else
{
marks.InnerHtml = "error";
}
dtrCheckAnswer.Close();
}
conn.Close();
//end check answer