Databases Reference
In-Depth Information
A couple of odd points in the FindOtherFieldTemplate method are worth special
attention. First, the ID of the target field template is determined by concatenating two
underscore characters with the column name. This is how
DynamicControl
generates IDs
of field templates in the current version, and the
UnleashedFieldTemplate
is forced to do
it explicitly because this API is not publicly accessible. If the implementation changes in a
future version of Dynamic Data, this code will be broken. Hopefully, the original
FindOtherFieldTemplate
actually works by then and you can simply remove this
workaround instead of fixing it.
The other odd point in the
FindOtherFieldTemplate
method is the additional check
performed by the
FindControlRecursively
method to ensure that the ID of the field
template actually matches the ID you are looking for. This is done to ignore the false posi-
tive matches from the
CheckBoxList
and
RadioButtonList
controls, which override the
FindControl
method and always return self, regardless of the control ID value that was
passed in.
The Default entity template gives your forms a plain single-column layout with labels on
the left and data controls on the right. You can control display names and order of proper-
ties on this form as well as specify which field templates should be loaded for different
properties. This is often adequate for simple entities that have a relatively small number of
properties. For larger entities, such as the Employee entity, this simplistic approach to
form layout can produce a rather long web page with extra space available on the right
side. Normally, when this happens, consider creating a custom entity template and specify
a more appropriate layout, perhaps with two columns of labels and data controls.
However, it is also possible to create a more sophisticated entity template that will do it
dynamically based on the metadata.
DisplayAttribute
defines a property called
GroupName
, which can be used to specify arbi-
trary strings for grouping controls on a dynamically generated page. For instance, you
could use values like “Contact”, “Address”, and “Organization” to generate HTML
f
ieldset
controls that display labels and data controls in group boxes similar to Windows
applications. Alternatively, you could also use group names such as “Left” and “Right” to
assign each of the properties of the Employee entity one of two columns that display side-
by-side. Here is a fragment of the Employee metadata class that shows an example of the
second approach:
[MetadataType(typeof(Metadata))]
partial class Employee
{
private abstract class Metadata
{
[Display(GroupName = “Left”, Order = 100)]
public object FirstName { get; set; }