tags:

views:

171

answers:

2

Say you had a config object

public class MyConfig{
 public int PageSize{get;set;}
 public string Title{get;set;}
}

and you want to automatically generate a asp.net form to edit the properties on this object.

Do you know of any frameworks to do this automagically?

I know of MS Dynamic data, but seems I need to have the whole stack (database, linq, objects) to get this up and running. So I was thinking of something simpler..

+1  A: 

I was under the impression that you could modify the T4 templates used by dynamic data (Not sure if you can remove the data access part).

Have you looked at just using T4 on its own.

Jonathan Parker
+1  A: 

Sorry for jumping in late. There are several ways to use Dynamic Data with POCO.

  1. Use the DynamicObjectDataSource which is found in Futures and Preview releases of Dynamic Data, starting with July 2008 Futures. When looking in a Preview release, it contains a Futures assembly, Microsoft.Web.DynamicData.dll.

  2. When using ASP.NET 4.0 (now in Beta), you can call a new extension method, EnableDynamicData(). See the "SimpleDynamicDataSamples" project that comes with DD Preview 4 and later.

Here's an example from that code that uses an ObjectDataSource and the POCO class called "Product".

[MetadataType(typeof(Product.Metadata))]
public partial class Product {
    public class Metadata {
        [Required]
        public string ProductName { get; set; }
        [Range(0, 100)]
        public decimal UnitPrice { get; set; }
    }
}

public partial class ObjectDataSourceSample : System.Web.UI.Page {
    protected void Page_Init() {
        // Extension method syntax
        ProductsList.EnableDynamicData(typeof(Product));

        // Explicit syntax
        // MetaTable table = MetaTable.CreateTable(typeof(Product));
        // MetaTable.MapControl(ProductsList, table);
        // ProductsList.ColumnsGenerator = new DefaultAutoFieldGenerator(table);
    }
}
Peter Blum