Data Dictionary App - Yikes!

R

Rbrt

I am writing an application that is data dictionary driven - users will have
the ability to create tables and add fields to those tables, and other users
will be able to do data entry into these tables, view them, etc...

The problem is in writing the code for data entry and display. I have tried
FormView, GridView, Generic Repeater controls, etc. but have not been able to
find a way to dynamically add the necessary textboxes, what have you, when
the structure of the table and fields is not known beforehand. Everything I
have seen about these controls tells me that you have to explicitly define
controls at design time by specifying each object in a DIM command (VB).

This used to be very easy using Control Arrays but if I understand
correctly, control arrays are not supported in ASP.NET.

Any suggestions?
 
B

bruce barker

all controls in asp.net are dynamic and created at runtime. its trivial to
add them. in asp.net all container controls have a Controls collection you
can add new control to:


TextBox t = new TextBox();
t.Id = "text1";
myContainter.Controls.Add(t);

you might also want to look at the asp.net MVC toolkit which is a better
framework for this type of application. also look at iron python or iron ruby
which are also much better languages for this type of application then vb.net
or c#. The new dynamic binding controls were designed with these languages in
mind.

-- bruce (sqlwork.com)
 
R

Rbrt

Won't work. I want to create a Form to display the data from a database that
I do not know the structure of. So I do a "SELECT * from " & strTblName...

....and I get a datatable. Now I find out not only what the table's data
might be, but also its fields....

It's time to present that data ...

so...

"Textbox t = new textbox" is not going to help because I cannot say what t
is in runtime, which is when I discover what the table fields might be...

I need to be able to say at runtime...

Textbox (datatable.fields(x).name) = new TextBox()...

or ...

Textbox(x) = new textbox

or something similar....
 
P

Peter Bromberg [C# MVP]

I don't see why you cannot do this. You just need to get the syntax correct.
For example (pseudocode, untested):

foreach( DataRow row in myDataTable.Rows)
{
foreach DataColumn col in myDataTable.Columns)
{
TextBox t = new TextBox();
t.ID = col.ColumnName;
t.Text = (string)row[col.ColumnName];
// add "t" to container control here, handle positioning
}


}
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 
R

Rbrt

The problem comes when you want to add the control to a PlaceHolder. You can
have only one TextBox t, right?

Peter Bromberg said:
I don't see why you cannot do this. You just need to get the syntax correct.
For example (pseudocode, untested):

foreach( DataRow row in myDataTable.Rows)
{
foreach DataColumn col in myDataTable.Columns)
{
TextBox t = new TextBox();
t.ID = col.ColumnName;
t.Text = (string)row[col.ColumnName];
// add "t" to container control here, handle positioning
}


}
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com


Rbrt said:
Won't work. I want to create a Form to display the data from a database that
I do not know the structure of. So I do a "SELECT * from " & strTblName...

...and I get a datatable. Now I find out not only what the table's data
might be, but also its fields....

It's time to present that data ...

so...

"Textbox t = new textbox" is not going to help because I cannot say what t
is in runtime, which is when I discover what the table fields might be...

I need to be able to say at runtime...

Textbox (datatable.fields(x).name) = new TextBox()...

or ...

Textbox(x) = new textbox

or something similar....
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top