我在更新面板中使用了 5 个单选按钮,但是当我第一次检查单选按钮时,它不会被选中更改。之后意味着第二次检查它的工作正常,所以请告诉应该是什么问题。这是我的代码
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:RadioButton ID="rbtn_A" runat="server" GroupName="rbt"
AutoPostBack="true" OnCheckedChanged="rbtn_A_CheckedChanged" />
<asp:RadioButton ID="rbtn_B" runat="server" GroupName="rbt" AutoPostBack="true"
OnCheckedChanged="rbtn_B_CheckedChanged" />
<asp:RadioButton ID="rbtn_C" runat="server" GroupName="rbt" AutoPostBack="true"
OnCheckedChanged="rbtn_C_CheckedChanged" />
<asp:RadioButton ID="rbtn_D" runat="server" GroupName="rbt" AutoPostBack="true"
OnCheckedChanged="rbtn_D_CheckedChanged" />
</ContentTemplate>
这是我的第一个单选按钮 c# 函数:protected void rbtn_A_CheckedChanged(object sender, EventArgs e) {
foreach (GridViewRow gv in dl_ques.Rows)
{
Label lblTest = (Label)gv.FindControl("lbltest");
Label lbl = (Label)gv.FindControl("lbl_qno");
RadioButton rbtn_A = (RadioButton)gv.FindControl("rbtn_A");
DataSet ds = new DataSet();
ds = getAnswer();
SqlCommand cmd1 = DataManager.getCommandSp("spGetIBPSTestQues");
cmd1.Parameters.AddWithValue("@Test_id", Convert.ToInt32(lblTest.Text));
DataSet dsorg = DataManager.getDataSet(cmd1);
if (ds.Tables[0].Rows.Count > 0)
{
SqlCommand cmd = new SqlCommand();
cmd = DataManager.getCommandSp("SpUpdateIBPSTestSolved");
cmd.Parameters.AddWithValue("@user_id", Convert.ToInt32(ht["UId"]));
cmd.Parameters.AddWithValue("@Ans", "A");
foreach (DataRow dr in dsorg.Tables[0].Rows)
{
if (Convert.ToInt32(lbl.Text) == Convert.ToInt32(dr["actual_que"]))
{
if (dr["actual_ans"].ToString() == "A")
{
cmd.Parameters.AddWithValue("@Ans_correct", "Yes");
}
else
{
cmd.Parameters.AddWithValue("@Ans_correct", "No");
}
}
}
cmd.Parameters.AddWithValue("@test_id", Convert.ToInt32(lblTest.Text));
cmd.Parameters.AddWithValue("@Test_dt", DateTime.Now);
cmd.Parameters.AddWithValue("@Ques_id", lbl.Text);
cmd.Parameters.AddWithValue("@LastTimeMin", timehdnmin.Value);
cmd.Parameters.AddWithValue("@LastTimeSec", timehdnsec.Value);
DataManager.WriteToDb(cmd);
}
else
{
SqlCommand cmd = new SqlCommand();
cmd = DataManager.getCommandSp("SpInsertIBPSTestSolved");
cmd.Parameters.AddWithValue("@user_id", Convert.ToInt32(ht["UId"]));
cmd.Parameters.AddWithValue("@Ans", "A");
foreach (DataRow dr in dsorg.Tables[0].Rows)
{
if (Convert.ToInt32(lbl.Text) == Convert.ToInt32(dr["actual_que"]))
{
if (dr["actual_ans"].ToString() == "A")
{
cmd.Parameters.AddWithValue("@Ans_correct", "Yes");
}
else
{
cmd.Parameters.AddWithValue("@Ans_correct", "No");
}
}
}
cmd.Parameters.AddWithValue("@test_id", Convert.ToInt32(lblTest.Text));
cmd.Parameters.AddWithValue("@Test_dt", DateTime.Now);
cmd.Parameters.AddWithValue("@Ques_id", lbl.Text);
cmd.Parameters.AddWithValue("@LastTimeMin", timehdnmin.Value);
cmd.Parameters.AddWithValue("@LastTimeSec", timehdnsec.Value);
DataManager.WriteToDb(cmd);
}
}
}