Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to show multiple questions with its choice from database in a single page at a time... and validate the answers with the selected options...
pass the score to next page...
how to do?
give me an idea....


[edit]Subject only - OriginalGriff[/edit]
Posted
Updated 17-Aug-17 3:11am
v3
Comments
Abhinav S 22-Sep-11 2:47am    
What have you tried? Which part of the project are you facing an issue with?
Raghupathiraja 22-Sep-11 3:00am    
i am developing online examination project...
in that i want to display random questions and its choices...
but i want to show multiple questions in a single page....
can u give me any solution....
OriginalGriff 22-Sep-11 2:49am    
Changed question title to meaningful description. Please do not use "please help me" or similar as it does not tell potential answerers what your problem is - that wastes time if they know nothing about databases. If you use a more descriptive title, you will get better focussed responses.

Hi,

I already gave you the code for it in yesterday i think

you've modify it to achieve your requirement.


Here again I'm sending the entire code for it .


HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language ="javascript" >
        var tim;
       
        var min = 20;
        var sec = 60;
        var f = new Date();
        function f1() {
            f2();
            document.getElementById("starttime").innerHTML = "Your started your Exam at " + f.getHours() + ":" + f.getMinutes();
             
            document.getElementById("endtime").innerHTML = "Your  time is :"+f.toLocaleTimeString();
        }
        function f2() {
            if (parseInt(sec) > 0) {
                sec = parseInt(sec) - 1;
                document.getElementById("showtime").innerHTML = "Your Left Time  is :"+min+" Minutes ," + sec+" Seconds";
                tim = setTimeout("f2()", 100);
            }
            else {
                if (parseInt(sec) == 0) {
                    min = parseInt(min) - 1;
                    if (parseInt(min) == 0) {
                        clearTimeout(tim);
                        location.href = "default5.aspx";
                    }
                    else {
                        sec = 60;
                        document.getElementById("showtime").innerHTML = "Your Left Time  is :" + min + " Minutes ," + sec + " Seconds";
                        tim = setTimeout("f2()", 100);
                    }
                }
               
            }
        }
    </script>
</head>
<body onload="f1()" >
    <form id="form1" runat="server">
    <div>
      <table width="100%" align="center">
        <tr>
          <td colspan="2">
            <h2>This is head part for showing timer and all other details</h2>
          </td>
        </tr>
        <tr>
          <td>
            <div id="starttime"></div><br />
            <div id="endtime"></div><br />
            <div id="showtime"></div>
          </td>
        </tr>
        <tr>
          <td>
              <asp:DataList ID="DataList1" runat="server" Width ="100%" 
                  onitemdatabound="DataList1_ItemDataBound" 
                >
                <HeaderTemplate >
                  <table width="100%" align="center">
                                 
                </HeaderTemplate>
                <itemtemplate>
                   <tr>
                     <td>
                       <table width="100%" border="1" bordercolor="green" cellspacing="0" cellpadding="0">
                         <tr>
                           <td>
                               <asp:Label ID="Label1" runat="server" Text='<%#Eval("qid") %>'> <%#Eval("qname") %></td>
                         </tr>
                         <tr>
                           <td>
                           <asp:RadioButtonList ID="RadioButtonList1" runat="server" >
           
                               
                                               
                           </td>
                         </tr>
                       </table>
                     
                     </td>
                   </tr>
               </itemtemplate>
          
                <footertemplate>
                    </footertemplate></table>
                
               
              
            
              <br />
            
              
          </td>
         
        </tr>
      </table>
      <br />
   

    </div>
    </form>
</body>
</html>


And the code behind file contains the following code

C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        MylocalDataClassesDataContext db = new MylocalDataClassesDataContext();
        var f = from d in db.QuestionTabs
                select d;
        DataList1.DataSource = f;
        DataList1.DataBind();

    }
}

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        RadioButtonList rdblist = (RadioButtonList)e.Item.FindControl("RadioButtonList1");
        Label lblqid = (Label)e.Item.FindControl("Label1");
        string qid = lblqid.Text;
        MylocalDataClassesDataContext db = new MylocalDataClassesDataContext();
        var f = from d in db.QuestionTabs
                where d.qid ==int.Parse (qid)
                select d;
        foreach (QuestionTab qt in f)
        {
            rdblist.Items.Add(new ListItem(qt.opt1, qt.opt1));
            rdblist.Items.Add(new ListItem(qt.opt2, qt.opt2));
            rdblist.Items.Add(new ListItem(qt.opt3, qt.opt3));
            rdblist.Items.Add(new ListItem(qt.opt4, qt.opt4));
        }
    }

}


And Database file is
SQL
/****** Object:  Table [dbo].[QuestionTab]    Script Date: 09/22/2011 13:47:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QuestionTab]') AND type in (N'U'))
DROP TABLE [dbo].[QuestionTab]
GO
/****** Object:  Table [dbo].[VideoTab]    Script Date: 09/22/2011 13:47:56 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VideoTab]') AND type in (N'U'))
DROP TABLE [dbo].[VideoTab]
GO
/****** Object:  Table [dbo].[VideoTab]    Script Date: 09/22/2011 13:47:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VideoTab]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[VideoTab](
	[vid] [int] IDENTITY(1,1) NOT NULL,
	[vname] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[vpath] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_VideoTab] PRIMARY KEY CLUSTERED 
(
	[vid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
)
END
GO
SET IDENTITY_INSERT [dbo].[VideoTab] ON
INSERT [dbo].[VideoTab] ([vid], [vname], [vpath]) VALUES (1, N'video1', N'video1.swf')
INSERT [dbo].[VideoTab] ([vid], [vname], [vpath]) VALUES (2, N'video2', N'video2.swf')
INSERT [dbo].[VideoTab] ([vid], [vname], [vpath]) VALUES (3, N'video3', N'video3.wmv')
SET IDENTITY_INSERT [dbo].[VideoTab] OFF
/****** Object:  Table [dbo].[QuestionTab]    Script Date: 09/22/2011 13:47:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[QuestionTab]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[QuestionTab](
	[qid] [int] IDENTITY(1,1) NOT NULL,
	[qname] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[opt1] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[opt2] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[opt3] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[opt4] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[ans] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_QuestionTab] PRIMARY KEY CLUSTERED 
(
	[qid] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
)
END
GO
SET IDENTITY_INSERT [dbo].[QuestionTab] ON
INSERT [dbo].[QuestionTab] ([qid], [qname], [opt1], [opt2], [opt3], [opt4], [ans]) VALUES (1, N'What is CLR', N'Common language Runtime', N'cdfdfLdfdf', N'hjhjh', N'jjhjhjh', N'Common language Runtime')
INSERT [dbo].[QuestionTab] ([qid], [qname], [opt1], [opt2], [opt3], [opt4], [ans]) VALUES (2, N'WWW stands for', N'dffd', N'hghjg', N'hghg', N'World Wide Web', N'World Wide Web')
SET IDENTITY_INSERT [dbo].[QuestionTab] OFF

Try the above code for your requirement.And modify it to achieve best results

All the Best
 
Share this answer
 
v3
Comments
Raghupathiraja 22-Sep-11 5:51am    
raghupathi.raja@gmail.com...
can u send it to me..
Muralikrishna8811 22-Sep-11 5:53am    
just copy from solution.

create DB and copy this code .
Member 13990156 8-Oct-18 4:08am    
Hi Muralikrishna,
can you please provide the code structure of class MylocalDataClassesDataContext .
MoM_Mohammad 23-Jun-21 6:38am    
Hello @Muralikrishna8811Watch
Please Help me.
I used your code for multiple Question with errors.
what is this in your code ?
MylocalDataClassesDataContext db = new MylocalDataClassesDataContext();
I am a beginner.please help me
Read from the database you should be able to do already, from your earlier questions.

Keep a session or user database based index which shows what question they are on. When you get the postback, you can read that back, and check if the answer they gave is the correct one. You then update either the session or the user database entry to show total progress. This then gets displayed on the page each time they work through, if you need to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900