Andrea Azzola

Technology, Personal Development and Financial Independence

Handle Multiple Columns as One with Dynamic Data

Posted on [Permalink]

I need to schedule some tasks with ASP .NET and save a "Start date" and an "Interval", stored respectively as date (DateTime) and long (TimeSpan.Ticks) in my database.

Editing ticks values is not exactly what I define good UX, so I binded the proper MetaColumn, to the proper UIHint. After a few tests, I noticed how my GUI was - working, but not easy to understand as I was expecting.

I decided to deeply customize the FieldTemplateUserControl of Dynamic Data, to display and save multiple Columns I needed (Start Date, Start Time, Occours - Daily, Weekly, Monthly.., etc...). The solution is really simple, but there are few points you may need to bear in mind:

How to retrieve values (Schedule_EditField.ascx.cs)

:
protected override void OnDataBinding(EventArgs e)
  {
    base.OnDataBinding(e);
    DateTime? startFrom = (DateTime?)Eval("StartFrom");
    long? timeIntervalTicks = (long?)Eval("TimeInterval");
    DateTime? lastExecution = (DateTime?)Eval("LastExecution");
  }

How to store values

protected override void ExtractValues(IOrderedDictionary dictionary)
  {
    dictionary["StartFrom"] = …; //logic here
    dictionary["TimeInterval"] = …;  //logic here
  }
Categories: ASP.NETDynamic Data