Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have around 15 templates (this will grow) and each template will have around 10-15 questions. Each question can have answers in different format like text box, list box, dropdown, radio button etc.

I need to show one template in a page, at a time based on the input I am getting.

What would be the best design approach for this?

  1. Put questions data in database and Create dynamic control?
  2. Putting in xml and display using xslt?
  3. Creating static set of templates?

Or any other approach? I don't have too much time to do this.

I am going to use Silverlight for this.

share|improve this question

You should use a database, and depending on the complexity of your questionnaires will determine how "wild" you need to go into self-referencing structures and such. I'm assuming you'll be using a Relational DB.

Considerations:

 1). Will the questions be unique per "questionaire" or re-used?
 2). Will each answer only belong to one Question or re-used across questionnaires?
 3). Will they ever want each answer to lead to a different "next" question? 

Depending on the above will determine the "object" model, whether in code or as a database object.

Why use a database?

 1). Because you'll be able to slap an admin tool on it at some point .
 2). You can store the answers to the questions "relationally" to the questions.

Now for the "types" of answers: textboxes, inputs, radios, checkboxes etc..

You're going to have to store an answer "type" (textbox, radio, input) on each possible answer that is stored in the DB (or XML). like a lookup table, or some other defined value indicating the control type to render.

Then in the client code, you're going to have to "resolve" them on the display side of things using a switch, or dynamic control building mechanism.

Now the tricky part is going to be when a "list of options" is required, like for a drop down. You'll have to have an "Answer with Associated Answers" type of reference, so you can pull the associated answers and if type "dropdown". However, you'd probably be better off rendering the "drop down" type answers as a "radio" button list since they provide the same "choose one of a set" / multiple choice type capability.

Here's some general direction based on my experience:

you'll need Structures something like: "Questionaire", "Questions", "Answers", and a "UserAnswers". then maybe a "JoinQuestionaireToQuestions" and a "JoinQuestionsToAnswers" if you want to get all reusable / fancy.

Then you'll look up the Quetsionaire you need to use, get all the questions and the answers for each question. And render them on the page using the dynamic control rendering mechanism you created.

Then either as they complete the Questionaire you store each response in the DB, or save each answer in the client and do one insert after they complete the form. You just keep the value of the input or form field and save that data as the answer "value".

Funny enough.. I recently brought an old project back to life that does something like this.. you can check out the javascript (built this 5+ years ago) on the page and see how i did it (it's not for the faint of heart) and it's more of a proof of concept, but it's all database driven and dynamically generated. Seriously just brought this back to life last week..

I put it under the URL: question commando , lol.. click on "discovery script" to start the Q and A. In my scenario, each answer can lead to a different question.

Anyhow, hope any of this helps...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.