如何在单击按钮时显示下一个问题 [英] how to display a next question on click of a button

查看:66
本文介绍了如何在单击按钮时显示下一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,我正在做在线考试的项目,因为我有一个问题模块在这里显示当我点击下一个按钮它应该转到下一个问题,但它不会去。





使用System;

使用System.Collections.Generic;

使用System.Linq ;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Data.SqlClient;

使用System.Configuration;

使用System.Web.Security;

使用System。数据;



公共部分班学生:System.Web.UI.Page

{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [dbconnection]。ConnectionString);

int i = 1;

Session [Number] = i;

protected void Page_Load(object sender,EventArgs e)

{

Session [Number] = i ++;

Label1.Text = Session [Number]。ToString();



con.Open();

SqlCommand cmd = new SqlCommand (选择*来自QuestionNo ='的问题++ Label1.Text +',con);

SqlDataReader dr = cmd.ExecuteReader();

if(dr .Read())

{

Label2.Text = dr [Question]。ToString();

Label3.Text = dr [Ans1]。ToString();

Label4.Text = dr [Ans2]。ToString();

Label5.Text = dr [Ans3 ] .ToString();

Label6.Text = dr [Ans4]。ToString();

}

con.Close( );



con.Open();

SqlCommand cmd1 = new SqlCommand(选择*来自Answers where QuestionNo ='+ Label1 .Text +',con);

SqlDataReader dr1 = cmd1.ExecuteReader();

if(dr1.Read())

{

Label8.Text = dr1 [Answer]。ToString();

}

con.Close();

}

protected void RadioButton1_CheckedChanged(object sender,EventArgs e)

{

if(RadioButton1.Checked)

{

Label7.Text = Label3.Text;

}

}

protected void RadioButton2_CheckedChanged(object sender,EventArgs e)

{

if(RadioButton2.Checked)

{

Label7.Text = Label4.Text;

}

}

protected void RadioButton3_CheckedChanged(object sender,EventArgs e)

{

if(RadioButton3.Checked)

{

Label7.Text = Label5.Text;

}

}

protected void RadioButton4_CheckedChanged(object sender,EventArgs e)

{

if(RadioButton4。已检查)

{

Label7.Text =标签6.Text;

}

}

protected void Button1_Click(object sender,EventArgs e)

{

if(Label7.Text == Label8.Text)

{

Label9.Text =你的答案是对的;

}

else

Label9.Text =你的答案不正确;

}

protected void Button2_Click(object sender,EventArgs e)

{

i ++;

Session [Number] = i;

Response.Redirect(Student.aspx);



}

}

The following is my code, m doing project on online examination in that i have a module of question to display in this when i click on next button it should go to the next question but it is not going.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Data;

public partial class Student : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
int i=1;
Session["Number"] = i;
protected void Page_Load(object sender, EventArgs e)
{
Session["Number"] = i++;
Label1.Text = Session["Number"].ToString();

con.Open();
SqlCommand cmd = new SqlCommand("Select * from Questions where QuestionNo = '"+Label1.Text+"'", con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label2.Text = dr["Question"].ToString();
Label3.Text = dr["Ans1"].ToString();
Label4.Text = dr["Ans2"].ToString();
Label5.Text = dr["Ans3"].ToString();
Label6.Text = dr["Ans4"].ToString();
}
con.Close();

con.Open();
SqlCommand cmd1 = new SqlCommand("Select * from Answers where QuestionNo = '" + Label1.Text + "'", con);
SqlDataReader dr1 = cmd1.ExecuteReader();
if (dr1.Read())
{
Label8.Text = dr1["Answer"].ToString();
}
con.Close();
}
protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked)
{
Label7.Text = Label3.Text;
}
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton2.Checked)
{
Label7.Text = Label4.Text;
}
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton3.Checked)
{
Label7.Text = Label5.Text;
}
}
protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton4.Checked)
{
Label7.Text = Label6.Text;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Label7.Text == Label8.Text)
{
Label9.Text = "Your Answer is correct";
}
else
Label9.Text = "Your Answer is incorrect";
}
protected void Button2_Click(object sender, EventArgs e)
{
i++;
Session["Number"] = i;
Response.Redirect("Student.aspx");

}
}

推荐答案

更改Button2_Click方法。





protected void Button2_Click(object sender,EventArgs e)

{

i ++;

会话[数字] = i;



Label1 .Text = Session [Number]。ToString(); //这是新添加的

Response.Redirect(Student.aspx);



}
Change the Button2_Click method.


protected void Button2_Click(object sender, EventArgs e)
{
i++;
Session["Number"] = i;

Label1.Text = Session["Number"].ToString(); // This is the new addition
Response.Redirect("Student.aspx");

}


这篇关于如何在单击按钮时显示下一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆