mcw92
03-10-2012, 07:53 PM
Hey,
im building a simple quiz using asp.net.
Im trying to pass on an int value from the Q1 page to the Q2 page,
This is the code i have:
Q1 Page
string sScore;
int score = 0;
protected void Page_Load(object sender, EventArgs e)
{
//Start Creating Question//
lblQuestion.Text = "What is the capital city of Ireland?";
if (!IsPostBack)
{
ArrayList list1 = new ArrayList();
list1.Add(new ListItem("Dublin", "1"));
list1.Add(new ListItem("Cork", "2"));
list1.Add(new ListItem("Sligo", "3"));
rbl.DataSource = list1;
rbl.DataBind();
}
//End Creating Question//
protected void btnNext_Click(object sender, EventArgs e)
{
Response.Redirect("Q2.aspx?score=" + score);
}
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbl.SelectedIndex == 0)
{
score++;
//score=1//
}
lblScore.Text = Convert.ToString(score);
int.TryParse(Request.QueryString["score"], out score);
// sScore = (string)Request.QueryString["score"];
//stringscore = Convert.ToString(intscore);
//lblScore.Text = stringscore;
//stringscore = (string)Request.QueryString["score"];
Q2 Page :
string sScore;
int selection1; int selection2; int selection3; int selection4; int selection5;
int score;
protected void Page_Load(object sender, EventArgs e)
{
//Start Creating Question//
lblQuestion.Text = "Who is Barack Obama?";
if (!IsPostBack)
{
ArrayList list2 = new ArrayList();
list2.Add(new ListItem("Irish President", "1"));
list2.Add(new ListItem("American President", "2"));
list2.Add(new ListItem("Batman", "3"));
rbl.DataSource = list2;
rbl.DataBind();
}
//End Creating Question//
//newscore = (string)Request.QueryString["score"];
//score = (string)Request.QueryString["score"];
score = int.TryParse(Request.QueryString["score"], out score);
lblScore.Text = Convert.ToString(score);
^^Should show the score from previous page, where if index 0(dublin) was picked, it would be 1.
}
So in basics, on Q1 page, int score is created, given a value of 1 when dublin is clicked(a label on Q1 page proves this), then i want to pass on score to Q2(keeping the value of 1), and show the score on a label on Q2 also(still 1)
It can be as simple as you like as this is for personal use.
Also if anyone has another way of storing the selected value from the radiobuttonlist, please add it :)
I have 5 q's and the score needs to be totaled at the final page.
im building a simple quiz using asp.net.
Im trying to pass on an int value from the Q1 page to the Q2 page,
This is the code i have:
Q1 Page
string sScore;
int score = 0;
protected void Page_Load(object sender, EventArgs e)
{
//Start Creating Question//
lblQuestion.Text = "What is the capital city of Ireland?";
if (!IsPostBack)
{
ArrayList list1 = new ArrayList();
list1.Add(new ListItem("Dublin", "1"));
list1.Add(new ListItem("Cork", "2"));
list1.Add(new ListItem("Sligo", "3"));
rbl.DataSource = list1;
rbl.DataBind();
}
//End Creating Question//
protected void btnNext_Click(object sender, EventArgs e)
{
Response.Redirect("Q2.aspx?score=" + score);
}
protected void rbl_SelectedIndexChanged(object sender, EventArgs e)
{
if (rbl.SelectedIndex == 0)
{
score++;
//score=1//
}
lblScore.Text = Convert.ToString(score);
int.TryParse(Request.QueryString["score"], out score);
// sScore = (string)Request.QueryString["score"];
//stringscore = Convert.ToString(intscore);
//lblScore.Text = stringscore;
//stringscore = (string)Request.QueryString["score"];
Q2 Page :
string sScore;
int selection1; int selection2; int selection3; int selection4; int selection5;
int score;
protected void Page_Load(object sender, EventArgs e)
{
//Start Creating Question//
lblQuestion.Text = "Who is Barack Obama?";
if (!IsPostBack)
{
ArrayList list2 = new ArrayList();
list2.Add(new ListItem("Irish President", "1"));
list2.Add(new ListItem("American President", "2"));
list2.Add(new ListItem("Batman", "3"));
rbl.DataSource = list2;
rbl.DataBind();
}
//End Creating Question//
//newscore = (string)Request.QueryString["score"];
//score = (string)Request.QueryString["score"];
score = int.TryParse(Request.QueryString["score"], out score);
lblScore.Text = Convert.ToString(score);
^^Should show the score from previous page, where if index 0(dublin) was picked, it would be 1.
}
So in basics, on Q1 page, int score is created, given a value of 1 when dublin is clicked(a label on Q1 page proves this), then i want to pass on score to Q2(keeping the value of 1), and show the score on a label on Q2 also(still 1)
It can be as simple as you like as this is for personal use.
Also if anyone has another way of storing the selected value from the radiobuttonlist, please add it :)
I have 5 q's and the score needs to be totaled at the final page.