Click here to Skip to main content
       

ASP.NET

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionRandomize Data of Groupboxes [modified]memberASPnoob5 Oct '12 - 23:38 
Hi All, I want to create an exam program consisting of questions and bunch of groupboxes each containing several radio buttons. Each question has a groupbox below it. The questions and their corresponding possible answers are stored on a database which will be bound to the the radio buttons at runtime. To answer an exam question, test takers will click on the radio button next to the correct answer. I would like to give each test taker a different test by rearrange the test questions by randomly changing the order of the questions and randomly changing the order of the possible answers. Randomizing the order of the questions is pretty straight forward using the Random Class to randomly display the questions but I don't know how to randomly bind data from the database to the radio buttons in the groupboxes. Please explain how this can be done or point me to a site where there's a tutorial on doing this if you know of one. Thanks in advance.

modified 6 Oct '12 - 11:42.

AnswerRe: Randomize Data of GroupboxesmemberVijayChauhan1237 Oct '12 - 20:10 
Hi Dear,
I have worked on this type of project...
The following is the stored procedure you can use for randomly getting the questions as well as the random options (answers) from the database.
This stored procedure covers almost your 80% of the work, only the thing is you have to bind it to the gridview . If you have any doubts in this you can comment.
 

//////////////////////////////////////////////////////////////////////////////////////
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER
Procedure [dbo].[GetRandomOptionsold]
(@class varchar(max),
@Subject varchar(max),
@ExamType varchar(max),
@School varchar(max)
)
 
as
 
Begin
 
Create
Table #Options(ID int identity(1,1),Fields nvarchar(10))
 
Insert
into #Options
 
Select
COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME='Questions' And COLUMN_NAME like 'O%' Order By NEWID()
 
--Select * from #Options

Declare
@RandomCols nvarchar(100)
 
Set
@RandomCols=''
 
Select
@RandomCols=@RandomCols+Fields+' ,' from #Options
 
--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O1,')
 
+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))
 
--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O2,')
 
+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))
 
--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O3,')
 
+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))
 
--Select @RandomCols

Set
@RandomCols=(Select REPLACE(Substring(@RandomCols,0,CHARINDEX(' ,',@RandomCols)+2),' ,',' as O4,')
 
+
SUBSTRING(@RandomCols,CHARINDEX(' ,',@RandomCols)+2,LEN(@RandomCols)))
 
--Set @RandomCols=SUBSTRING(@RandomCols,0,len(@RandomCols))

--Select @RandomCols

Declare
@strQry nvarchar(MAX)
 
Set
@strQry=''
 
Set
@strQry='Select qno,que,'+@RandomCols+'ans from Questions where Class='''+@Class+''' and Subject='''+@Subject+''' and ExamType='''+@ExamType+''' and School='''+@School+''''
 
exec
(@strQry)
 
End
 
//////////////////////////////////////////////////////////////////////
AnswerRe: Randomize Data of GroupboxesmemberVijayChauhan1237 Oct '12 - 20:46 
If it has not solved your problem , please let me know ...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid