+1  A: 

Sure. This is off the top of my head, but I believe you could connect your class to an ObjectDataSource component which would in turn connect to a DetailsView control. So it's a hair more work, but it would be pretty trivial to have a method that created the needed items on the fly and bound them together.

Joel Coehoorn
I was in mid-post with the same answer when I saw yours. I added a link to the MSDN documentation.
tvanfosson
+1  A: 

You can do it with reflection. Using reflection, you can enumerate over the members of a class, and therefore create a form to edit the members.

Creating the code for rendering the web form based on the members of the class is a bit more code then I'm willing to type out here, but if you look into reflection you should be able to come up with your own solution in a couple hours.

Kibbee
I am aware of reflection and could do this but I know Rails is so popular because this type of functionality came out of the box, so to speak. Also, it would not be trivial to create this type of behaviour when you entered into more complex UML relationships like aggregtaion etc
Petras
+1  A: 

This is called "Scaffolding".

It really depends on what you are using for your data layer or ORM. Entityspaces, for example, comes with a scaffolding generator.

gregmac
+1  A: 

Absolutely! Scaffolding in Ruby is known as Dynamic Data in ASP.NET. Scott Hanselman speaks to Dynamic Data here.

There's a screen cast from Scott Hunter that shows it off here. It's of note that it's pretty new (still in beta).

Tyler
+1  A: 

You can for simple sites/purposes but it quickly breaks down when you want to do something more complex. Like what happens if you don't want certain fields to be visible, what happens if you have a relationship to a subset of a certain class etc.

Having been down this path before I'm guessing you came at the issue by realizing that:

  1. You spend alot of time creating similar forms/lists etc for similar entities.
  2. You want to minimize this time and are considering if your forms can be automatically generated.

Basically, if you want it to be done automatically then you'll end up creating an overcomplicated system that does half of what you want and actually takes longer to implement.

If however, you want to drastically cut the amount of time doing and maintaining writing repetitive gui code then then I suggest using a declarative style form builder and table builder (like the form builder in ROR).

This lets you quickly create forms/tables without repeating yourself any more than necessary and also gives you the flexibility that you need for complex scenarios.

flukus
You sum up my situation precisely.I am also coming from an interest in Rails which seems to come with this functionality directly in the langauge. So I assumed someone was going to add something similar to ASP.NET
Petras
In ASP.NET you should look into using templated user controls. This works fairly well but there are definitely some hard limitations from using the asp view engine.For the next version of our form.table builder (that we use in house) we're considering an anonymous method approach.
flukus