Hi I want to write a questionnaire web application in ASP .NET forms with C#
The users need to be able to add new questions and archive old ones so I have my form details in one table and the questions and answers in seperate tables.
Some pages have a set each of 10-15 questions and the answers must be inserted or updated together when the user clicks save/continue.
Can someone please suggest how to approach this? Should I be using the DetailsView or should I read up on writing my own data control for it (something I've haven't done yet.). Any pointers or examples with code I could look at would be very welcome.
BTW I've already looked into some of the open source controls for handling this via XML and they aren't flexible enough for what I need.
I've used formView and datagrid for inserts and updates in a past project, but these don't allow me to submit a bunch of answer at once click
QuestionID
QuestionText :you want to display
InputType : question control type (textbox ,radio button)
Mandatory: required or not
ValidationExpression : for regular express
Sequence: sequence of the question
IsArchive :Archived
Create a table QuestionResponse
UserID
QuestionID
QuestionResponse
LastModifiedAt
Create a usecontrol , create all the controls dyanmically . as
If InputType=1 then create Textbox
If InputType=2 then create DateControl etc
Apply all above attribuite to control as required.
I kept all data in ViewState and did all operations on it. (A single object for the questionair, holding a collection of questions.) Then on the save button I submitted all that data to the database. The outer DataControl was a DetailsView, with all others
nested inside it. (But they could have been side-by-side just as well.) The save button was the DetailsView Edit Button. Save was handled in the ItemUpdating handler of the DetailsView.
FormView should work just like DetailsView. All Data Controls typically work on a single item at a time. However, in the ItemUpdating handler you can do what you want. If you have more data, that's no problem to your code.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
linda_petty
Member
3 Points
20 Posts
questionnaire application, multiple inserts ASP & C#
Mar 27, 2012 04:09 PM|LINK
Hi I want to write a questionnaire web application in ASP .NET forms with C#
The users need to be able to add new questions and archive old ones so I have my form details in one table and the questions and answers in seperate tables.
Some pages have a set each of 10-15 questions and the answers must be inserted or updated together when the user clicks save/continue.
Can someone please suggest how to approach this? Should I be using the DetailsView or should I read up on writing my own data control for it (something I've haven't done yet.). Any pointers or examples with code I could look at would be very welcome.
BTW I've already looked into some of the open source controls for handling this via XML and they aren't flexible enough for what I need.
I've used formView and datagrid for inserts and updates in a past project, but these don't allow me to submit a bunch of answer at once click
sql server 2005, ASP.NET 3.5 VS 2008
robwscott
Star
8079 Points
1491 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 27, 2012 04:16 PM|LINK
so let me get the straight...
Page
Q1 A1 (textbox)
Q2 A2 (textbox)
........
button (Submit)
are all these answers going to be textboxes, or are they going to be radiobuttons/dropdownlist/checkbox/textbox combos??
are you saving these answers to a DB?? are you comparing the answer the user gave to the answer in the DB?
are the questions in a DB?
in your DB (if you have) - can you give me the columns?
i'm assuming you'd have something like...
TABLE
Column
ID Question Answer
Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
mcupryk
Member
243 Points
393 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 27, 2012 06:33 PM|LINK
Each table can correspond to a grid.
Bind your table (Select * from Answers...) datagridAnswers
Bind your table (Select * from Questions..) datagridQuestions.
I would create your own user control. You can download on google a user master detail datagrid control.
linda_petty
Member
3 Points
20 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 08:40 AM|LINK
There's some variety in required responses to questions...
all questions have have answers that are either Y/N or or Y/N/not applicable so these could be drop Down Lists or radio buttons
and most, not all, have a date as well (a validated text box)
one has a small text box or field too
yes I'm writing to a database - sql server 2005, ASP.NET 3.5 VS 2008
examples
Question Response Date AdditionalInfo
Has A been Done ? Y/N/n.a 12/02/12
Has B been done? Y/N not reqd
Has C been done? Give code. Y/N 15/02/12 code123456
Save&ContinueButton>>>
Thanks
linda_petty
Member
3 Points
20 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 08:46 AM|LINK
mcupryk you said "You can download on google a user master detail datagrid control."
Thanks. Can you tell me a good place to look for controls like this?? I need it to be free :-)
Are there any particular sites you have found useful?
linda_petty
Member
3 Points
20 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 08:48 AM|LINK
I'm thinking of using a GridView for the questions and answers and using a loop to insert all the rows on submit.
Does this sound a plausible approach?
paritoshmmec
Participant
1555 Points
304 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 09:00 AM|LINK
Create a table with following question columns
QuestionID
QuestionText :you want to display
InputType : question control type (textbox ,radio button)
Mandatory: required or not
ValidationExpression : for regular express
Sequence: sequence of the question
IsArchive :Archived
Create a table QuestionResponse
UserID
QuestionID
QuestionResponse
LastModifiedAt
Create a usecontrol , create all the controls dyanmically . as
If InputType=1 then create Textbox
If InputType=2 then create DateControl etc
Apply all above attribuite to control as required.
Please let me know in case of more help
Thanks and Regards,
Paritosh
linda_petty
Member
3 Points
20 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 09:06 AM|LINK
Thanks paritoshmmec, you said "Create a usercontrol , create all the controls dynamically"
Does this mean I simply place each of the controls inside a form tag then code behind the inserts with c# ?
Does this effectively mean I need to hard-code each of the questions?
superguppie
All-Star
48225 Points
8679 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 11:26 AM|LINK
Recently did something like that.
I kept all data in ViewState and did all operations on it. (A single object for the questionair, holding a collection of questions.) Then on the save button I submitted all that data to the database. The outer DataControl was a DetailsView, with all others nested inside it. (But they could have been side-by-side just as well.) The save button was the DetailsView Edit Button. Save was handled in the ItemUpdating handler of the DetailsView.
FormView should work just like DetailsView. All Data Controls typically work on a single item at a time. However, in the ItemUpdating handler you can do what you want. If you have more data, that's no problem to your code.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
paritoshmmec
Participant
1555 Points
304 Posts
Re: questionnaire application, multiple inserts ASP & C#
Mar 28, 2012 11:33 AM|LINK
First way:
1. put user control inside a grid or repeater
2. Bind questionTable to grid.
3. On RowCreated Event pass the questionid to UserControl where you have the logic to create Controls at runtime.
4. Set the response inside a control
Second way of doing it .
1. Make a Loop of all question and create the control dyanmicaly. add this to placeholder Like this
for(i=0;i<questions.count;i++;){
//switch case for question[i].inputtype
//add to placeholder.
}
Thanks and Regards,
Paritosh