Dynamic ASP page on the fly using C#

D

Dmitri Shvetsov

Hi All,

Is it possible at all, and if yes, then how? Or it's very/extremely hard to
do that? Maybe somebody knows...)

I'm writing a Web App using VS2003/C#/MSSQL.

I'm currently having about 100 different questions, some questions are
having relations to another questions and should be published only if the
parent has an answer, the most part of the questions should have answers,
some don't. The type of the questions can be very different - Simple Text,
RadioButton Lists, CheckBox Lists, CheckBox MultiSelection Lists, DropDown
Lists, and few more. The questions can be changed any time and we can not
write a hardcoded asp web page with all these questions and answers. So I
need some approach that can help me to create an ASP page on the fly using
the question list, the answer list, the questions type, etc. The ideal way -
if we can edit these answers. And all questions and answers should be shown
on one, maybe long web page.

Any standard grid that I know doesn't work, because I need to show all these
question types friendly to the client and regarding to the database
information.

What can I do? Use a Tree View to show all questions or what? I'm not
absolutely sure that it will work. It's not a Windows Application, it's a
Web Application with its own restrictions of the interface.

Any ideas or suggestions? Maybe somebody has already done a project like
this? Can I do something without grid? And what approach can be used to show
all this information dynamically?

Thanks,
Dmitri
 
G

Guest

I recently made a page that needed to create items from the results of a database. I didn't opt for a datagird or list because I wanted more functionality and things like drop down lists and buttons
I used a data repeater
What this does is write out a certain html item template per item in the collection or data object you bind it to
For example I had an object called Garment, this had an image, a selection of sizes, selection of colours, price and of course name
I created a template with labels, images, dropdownlists and a button to select the item
You can store the questions in a database and modify the DB to update the site

Getting a handle on the items after they've been made is a little more tricky. I found it useful to add made up tags to the controls that would tell me which item they pertained to
e.g (psuedocode
<asp:Repeater id = repeater1 runat = server><ItemTemplate><table style = "Z-Index = 105 Left =<%# GetLeft() %> Top = <%# GetTop() %>"><tr><td
// The databinder.Eval returns the name property, field or column depending on what you are binding it to
<asp:Label id = label runat = server value = <%# DataBinder.Eval(Container.DataItem, "Name") %> madeUpTag = <%# GetNumber()%>></td></tr></table></ItemTemplate></asp:Repeater

In the .cs behin

protected System.Web.UI.WebControls.Repeater repeater1
int left
int top
int number
protected string GetLeft(

return left.ToString()

protected string GetTop(

top+=20
return top.ToString()

protected string GetNumber(

number++
return number.ToString()

protected Page_Load(

if(IsPostBack!=true

ArrayList al = FunctionToGetStuffFromDB()
repeater1.DataSource = al
repeater1.DataBind()



If you want to use drop down lists I found the only way to populate them is by cycling through all of the controls in repeater1 then all the controls in the template
If you've used your made up attributes you can find out which item it is and databind the dropdown accordingly
One word of warning, when you databind the drop down list you lose any made up tags, so it's best to

string myMadeUpAttribute = ddl.Attributes["myMadeUpAttribute"]
ddl.DataSource = someArrayList
ddl.DataBind()
ddl.Attributes["myMadeUpAttribute"] = myMadeUpAttribute

do that

I hope that helps, and if anyone knows a better way I'd like to know about it

jax
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top