Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am creating a online Quiz.
I want to get the Questions from the database and display it in my aspx page.
I need to use for each loop for getting each questions and displaying it.
I stored every question in a object.
How can i display it??
Thanks!
Posted
Updated 26-Apr-12 21:50pm
v2
Comments
Sergey Alexandrovich Kryukov 4-Apr-12 1:39am    
This is not even a correct English phrase, so, it's really hard to understand what are you talking about. Perhaps you should try your questions on your colleagues and post them only if someone would understand something. Put a lot more detail, provide comprehensive explanation of your goal and your concerns. "Improve questions" is above.
--SA
Anderson8055 19-Apr-12 2:05am    
I am sorry for that.
Just now i noticed my mistake
Mohamed Mitwalli 4-Apr-12 2:38am    
you mean looping and store the items in array or what do u mean ?

Hello

i think u want to do is something like

u have

1 - database
2 - Class for fetching data using query or stored procedure
3 - form to display questions .

make One function in Class for having all data from database
get all that data on form using class object and save it in one List<class>

add datasource to the control on which you want to display you data .


good luck ..


what you did cannot iterate because foreach loop iterate on enumerable type .
and your object will not have all data .it will contain only last item from the database .

so for getting all data you will need to add object in a class type List after that you can use for each loop on the List
 
Share this answer
 
v2
Comments
Anderson8055 30-Apr-12 8:04am    
Brilliant answer Gauravupadhyay...
While creating class for the Question we should store the Questions in a list.
From the list of questions we can use foreach loop and display each question one by one..
 
Share this answer
 
v2
C#
{
       dt =HttpContext.Current.Session["Answered"] as DataTable;
       foreach(DataRow row in dt.Rows)
       {
           if(row["Id"].ToString()==Label2.Text)
           {
               row["Selected"]=Convert.ToInt32(RadioButtonList1.SelectedIndex)+1;
               HttpContext.Current.Session["Result"] = dt;
           }
       }
       dt = HttpContext.Current.Session["Result"] as DataTable;
       foreach (DataRow row in dt.Rows)
       {
           if (row["Selected"].ToString() == row["CorrectOption"].ToString())
           {
               marks = marks + 1;
           }
       }
       HttpContext.Current.Session["Marks"] = marks;
   }
 
Share this answer
 
Comments
Anderson8055 2-May-12 1:08am    
Copy all the contents from database to datatable.
From datatable we can get the values of each datarow using for each loop

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