如何点击“下一步”按钮获取下一个数据行

本文关键字:下一步 下一个 数据 获取 何点击 按钮 | 更新日期: 2023-09-27 18:00:47

我想从表中获取下一条记录,显示为Question。使用以下代码,我无法从表中获取下一个Question

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack == false)
    {
        Quiz_Load();
    }
}
private void Quiz_Load()
{
    try
    {
        if (Session["UserQuizID"] != null)
        {
            string mayank = "mm.bhagat";
            string UserQuiz_ID = Session["UserQuizID"].ToString();
            SqlConnection con = new SqlConnection(c);
            SqlCommand cmd = new SqlCommand("select top 0.1 percent QuestionID, Title, Answer1,Answer2,Answer3,Answer4,UserAnswer from [Table_UserAnswer] WHERE UserQuizID = '" + UserQuiz_ID.ToString() + "' AND UserName = '" + mayank.ToString() + "' order by newid()", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Session["QuestionID"] = dr[0].ToString();
                Lbl_QuestionTitle.Text = dr[1].ToString();
                RadBut_Answer.Items.Add(dr[2].ToString());
                RadBut_Answer.Items.Add(dr[3].ToString());
                RadBut_Answer.Items.Add(dr[4].ToString());
                RadBut_Answer.Items.Add(dr[5].ToString());
                Session["UserAnswer"] = dr[6].ToString();                   
            }
            else
            {
            }
            con.Close();
        }
        else
        {
            Response.Redirect("Start.aspx");
        }
    }
    catch
    {
    }        
}
protected void RadBut_Answer_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        int getvalue;
        getvalue = Convert.ToInt32(RadBut_Answer.SelectedIndex + 1);
        Lbl_SelectedAnsMsg.Text = MessageFormatter.GetFormattedAlertsMessage("Your Selected Answer is : " + getvalue.ToString());
        Session["UserAnswer"] = getvalue.ToString();
    }
    catch
    { 
    }
}
protected void But_Next_Click(object sender, EventArgs e)
{
    UpdateUserAns();
    if (Session["UserAnswer"] == null)
    {
        Response.Redirect("Result.aspx");
    }
    else
    {
    }
}
private void UpdateUserAns()
{
    try
    {
        string mayank = "mm.bhagat";
        string UserQuiz_ID = Session["UserQuizID"].ToString();
        string Question_ID = Session["QuestionID"].ToString();
        string User_Answer = Session["UserAnswer"].ToString();
        SqlConnection con = new SqlConnection(c);
        SqlCommand cmd = new SqlCommand("UPDATE Table_UserAnswer SET UserAnswer='" + User_Answer.ToString() + "' WHERE UserQuizID = '"+ UserQuiz_ID.ToString() +"' AND QuestionID = '"+Question_ID.ToString()+"' AND UserName = '"+mayank.ToString()+"'", con); 
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        cmd.Cancel();
    }
    catch
    {
    }
}

如何点击“下一步”按钮获取下一个数据行

嗨,在这里查看这个帖子客户端

在这里,您可以找到问题的解决方案