Solved

Dynamic questionnaire asp.net VB/ C#

Posted on 2009-04-03
6
5,154 Views
Last Modified: 2012-05-06
Hello!

Im working on a dynamic questionnaire for a company, but Im really starting to think if the approached ive chosen is the best way to go.

Im getting the data from a databasetable, filling a dataset in my application with the data recieved and then i loop it through and add the data in a placeholder.

Language: ASP.net VB or C# doesn't matter
----------
The table consists of radiobutton questions, checkradiobutton questions and might aswell have an image url.
I feel like its hard to create any nice design.ive used a reapeater with content templates  in previous works ive done. Is it possible somehow to do like a template for a radiobuttonlist, checkbuttonlist etc and just fill template with data instead of just adding like I do now with no actual idea of what is to be created.

Would be really glad if anyone could help me, give me some ideas /code on how to do it
Kindly regards Clooak
0
Comment
Question by:clooak
  • 3
  • 2
6 Comments
 
LVL 10

Assisted Solution

by:MaxOvrdrv2
MaxOvrdrv2 earned 50 total points
ID: 24063144
well, you can always just define a single parameter as your drop-down or whatever you're building, and while looping through the dataset, for each row, reset the parameter, assign, and post...

dim row as datasetrow (or something like that)
dim itm as new listitem
dim dd as new dropdownlist
dd.Id="whatever"
for each row in ds.tables(0).rows
itm=new listitem
itm.value=row.item("fieldname")
itm.text=row.item("fieldname")
dd.items.add(itm)
next
me.containerID.items.add(dd)

something like this if you catch my drift. Unless i'm completely out of the picture with what i think you're trying to do ;)

M

0
 
LVL 9

Expert Comment

by:kprestage
ID: 24064083
We do something very similar and actually create User Controls for each "Question Type".  Then as we read in the questions from the database, we dynamically add the required control to the page in the proper order.  
0
 

Author Comment

by:clooak
ID: 24129620
kprestage, how would u check their answers later on if its i a usercontrol?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 9

Accepted Solution

by:
kprestage earned 200 total points
ID: 24129750
Just create a property on the user control called "Answer" that returns the currently selected answer.  For example, lets say you have 2 types of questions "text" and "selectone".  For a text question, you will display a textbox for the user to enter an answer, for the selectone, it would be a dropdown box.  You create a property in the UserControl like this:


Public String Answer(){

get 

{

   switch (myquestiontype)

   {

       case "selectone":

          return DropDown1.Text;

       case "text":

          return TextBox1.Text;

   }

{

}

Open in new window

0
 

Author Comment

by:clooak
ID: 24129857
Okay thanks alot for the help, I guess I could just loop through the answers if i want several answers to be "correct"  So one control for each customfield etc for radiobuttonlist, checkbuttonlist and normal textfields right? Not every single one of them combined in to one?

It sounds like a really good idea, I will give it a try, thanks! Points will be handed out by the end of the day as soon as ive tried the advice
0
 
LVL 9

Expert Comment

by:kprestage
ID: 24129922
If you will have a question that allows multiple answers, you can simply change your "Answer" property to return a string[] array rather than just a string.  In our case, we actually return an Answer Class which has a description and generic<T> value property.  So our Answer Property actually returns List<Answer> rather than a string or string array.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now