简体   繁体   中英

Dynamic Survey Form in asp.net

I currently have a db structure that looks something like what i have below and i was wondering what the best way would be to go about building dynamic forms based on the DB for the Question & Answer input portion. Also what is the safest way to do this?

QuestionID | Question                                                              | DisplayOrder
--------------------------------------------------------------------------------------
1          | Enter the addresses you have lived at in the last 10 years            | 1
2          | How much wood could a woodchuck chuck if a woodchuck could chuck wood | 2


AnswerID | QuestionID | Answer           | AnswerValueType        | DisplayOrder
-----------------------------------------------------------------------------
1        | 1          | Address                 | Text            | 1
2        | 1          | City                    | Lookup          | 2
3        | 1          | State                   | Lookup          | 3
4        | 2          | Enter your guesstimate  | Text            | 1


ResponseID| PersonID | QuestionID | AnswerID | AnswerValue
--------------------------------------------------------------
1         | 1        | 1          | 1        | 123 W Fake St
1         | 1        | 1          | 2        | Las Vegas
1         | 1        | 1          | 3        | Nevada
2         | 2        | 1          | 1        | 456 W Fake St
2         | 2        | 1          | 2        | Seattle
2         | 2        | 1          | 3        | Washington
1         | 1        | 2          | 1        | What a dumb question

Thanks in advance

Scott Mitchell put together a great 4 part tutorial titled " Creating a Dynamic Data-Driven User Interface " that dynamically builds user interfaces based on a data model. You're probably looking at a lot of work and testing but it can be done.

You should also check out the 4 part video series, " Building a Quiz Engine ", at www.asp.net and see if it helps. The more you can see of ways of this being done, the better.

It is funny someone mentions Scott Mitchell, because at a conference I asked him a pretty similar question and he CC'd me on an email to David Fowler who wrote a blog post about the subject. Basically, the answer he gave me was that the ASP.net team has lots of interesting ideas for Controls that will will make problems like these much easier to solve, but they are hard to get into final release builds. One such control was the "SpecialRepeater" which I think about more like a Recursive Repeater.

The blog post is here : External ITemplates and Hierarchical Databinding

Basically, you throw an ObjectDataSource on your page, you bind each Question object to your OuterTemplate and then you set the DataSource property on your InnerTemplate to be the QuestionOption property from your original question.

This of course assumes you have some kind of data model that will allow you to return a Question object with a property called "QuestionsOptions" or something that is a collection of another type with all the special properties you need.

As a side note, the whole thing seems like something that can be handled pretty easily by doing the old "OnDataBound()" trick...and sometimes it can...but that always muddies the code-behind and this control is pretty fancy at making the whole process completely declarative on the .aspx side of things...

建立表格的最佳方法是编程方式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM