Morning,
I am writing a simple quiz app. I am getting my questions and answers from the my MS SQL DB. How would i go about getting this and putting it into say a repeater control, so i can display 6 questions, with their answers.
Or... do you know of a better way to do this?
var questions = dc.Questions.ToList().OrderBy(q => Guid.NewGuid()).Take(6);
foreach (var q in questions)
{
litQuestion.Text = q.question1;
int qId = q.id;
var ans = dc.Answers.Where(a => a.questionId == qId).ToList();
litAnswer1.Text = ans[0].answer1.ToString();
litAnswer2.Text = ans[1].answer1.ToString();
litAnswer3.Text = ans[2].answer1.ToString();
}
dc is my datacontext.
Thanks in advance.