using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test : System.Web.UI.Page
{
static student stu1 = new student();
String table = "exam";
static int a = 1;
static Random r = new Random();
protected void Page_Load(object sender, EventArgs e)
{
String query = "select * from exam ";
stu1.read1(query, table);
/*Label2.Text = stu1.st[0].ToString();
Label3.Text = stu1.st[1].ToString();
Label4.Text = stu1.st[2].ToString();
Label5.Text = stu1.st[3].ToString();
Label6.Text = stu1.st[4].ToString();*/
questionLabel.Text = (stu1.ds1.Tables[table].Rows[stu1.st[0]][1]).ToString();
op1RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[0]][2]).ToString();
op2RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[0]][3]).ToString();
op3RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[0]][4]).ToString();
op4RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[0]][5]).ToString();
}
protected void nextButton_Click(object sender, EventArgs e)
{
if (op1RadioButton.Checked || op2RadioButton.Checked || op3RadioButton.Checked || op4RadioButton.Checked)
{
op1RadioButton.Checked = false;
op2RadioButton.Checked = false;
op3RadioButton.Checked = false;
op4RadioButton.Checked = false;
}
prevButton.Visible = true;
if (a < 5)
{
questionLabel.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][1]).ToString();
op1RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][2]).ToString();
op2RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][3]).ToString();
op3RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][4]).ToString();
op4RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][5]).ToString();
++a;
}
else
{
prevButton.Visible = false;
Response.Redirect("Results.aspx");
}
}
protected void prevButton_Click(object sender, EventArgs e)
{
if (op1RadioButton.Checked || op2RadioButton.Checked || op3RadioButton.Checked || op4RadioButton.Checked)
{
op1RadioButton.Checked = false;
op2RadioButton.Checked = false;
op3RadioButton.Checked = false;
op4RadioButton.Checked = false;
}
if (a > 0 && a < 5)
{
--a;
questionLabel.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][1]).ToString();
op1RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][2]).ToString();
op2RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][3]).ToString();
op3RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][4]).ToString();
op4RadioButton.Text = (stu1.ds1.Tables[table].Rows[stu1.st[a]][5]).ToString();
}
else
prevButton.Visible = false;
}
}
i tried to run the application on two or more machines, but i was getting the same set of random questions on all clients. but,i want my application to generate different random questions for different clients. so please help me out!!!
below is the code for the class which i've used:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
using System.Data;
/// <summary>
/// Summary description for Class1
/// </summary>
public class student
{
public int[] st = new int[5];
int i,j;
static Random r = new Random();
const String connString1 = " Data Source=.\\SQLEXPRESS; AttachDbFilename=|DataDirectory|\\Student11.mdf; Integrated Security=True; User Instance=True ";
const String connString2 = " Data Source=.\\SQLEXPRESS; AttachDbFilename=|DataDirectory|\\Questions.mdf; Integrated Security=True; User Instance=True ";
SqlConnection conn1 = new SqlConnection(connString1);
SqlConnection conn2 = new SqlConnection(connString2);
public DataSet ds=new DataSet();
public DataSet ds1 = new DataSet();
public student()
{
//
// TODO: Add constructor logic here
//
for(int k=0;k<5;k++)
st[k]=-1;
for (j = 0; j < 5; j++)
{
abc:
i = r.Next(1, 25);
for (int k = 0; k < 5; k++)
{
if (i == st[k])
goto abc;
}
st[j] = i;
}
}
public int insert(String query)
{
int a;
SqlCommand cmd = new SqlCommand(query, conn1);
conn1.Open();
a=cmd.ExecuteNonQuery();
conn1.Close();
return a;
}
public void read(String query, String tab)
{
SqlDataAdapter adp = new SqlDataAdapter(query,conn1);
adp.Fill(ds,tab);
}
public void read1(String query, String tab)
{
SqlDataAdapter adp = new SqlDataAdapter(query, conn2);
adp.Fill(ds1, tab);
}
}

New Topic/Question
Reply



MultiQuote






|