I'm not much experienced with asp.net development. I have a database for a kind of quiz application, answers to which are then processed through logic to generate or determine a plan for the user.
I have two tables in the database 1)Questions table with Qid(P key), Q description etc.
2)QuestionAns table which contains all the answer options for every question in the question table. Columns are QueAnsId(P. Key),Qid(foreign key), Answers(all answers options for every question).
I created two datasets for each of these tables using the configuration wizards. 1)QuesDS,
On their respective tableAdapters, i have written methods GetQuestions(), GetAnswersByQuesId(Qid)containg respective sql queries.
What i want to achieve is, for each question displayed , a dropdownlist with all the answer options for that question be displayed. Then a question again and A dropdownlist again and so on. The answer dropdownlists should be generated dynamically based on number of questions in the question table. I can get the questions to print but not the answers list.
My questions are:
1)Is a Dataset solution appropriate for this or should i be using a datareader?
2)Am i on the right track or is this the appropriate way of what i am trying to achieve?
3)Get the dropdownlists to work.
Code for this follows below:
public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
QuesDSTableAdapters.QuestionTableAdapter questionsAdapter = new
questions = questionsAdapter.GetQuestions();
AnsDSTableAdapters.QueAnsTableAdapter queansAdapter = new
// AnsDS.QueAnsDataTable queans;
foreach (QuesDS.QuestionRow quesRow in questions)
Response.Write("Question: " + quesRow.Que + "<br />");
answer = queansAdapter.GetAnswersByQuestionId(quesRow.QID);
DropDownList ddl = new DropDownList() ;
// ddl.DataSource = queansAdapter.GetAnswersByQuestionId(Convert.ToInt32(quesRow.QID));
ddl.DataSource = answer;
// DropDownList1.Items.Add(Convert.ToString(answer.Columns ["Answer"]));
ddl.DataTextField = "Answer";