Question

I was watching a tutorial on Rails and was very impressed that you could so easily create an editing system for a class just by defining it.

Can this be done in ASP.NET?

I know there are ORMs out there, but do they come with an editing system?

To explain what I mean by an editing system, consider a class for defining people

class Person
{
  string First_Name;
  string Last_Name
}

And then perhaps with one bold stroke something like this:

CreateEditAbleClass(Person)

You would get the functionality below in a browser:

http://www.yart.com.au/images/orm_editor.jpg

And this functionality would extend to all the UML definitions – inheritance, association, aggregation etc. In addition, there would be a simple way of adding customisable validation and so forth.

I currently use DataGrids and a lot of manual coding to achieve these results.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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).

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top