Databases Reference
In-Depth Information
LISTING 11.1 Continued
}
return dictionary;
}
}
}
Implementation of the overridden FieldValueString property getter is straightforward. It
calls the GetEnumDictionary method to retrieve the dictionary with display names and
values of the enum items and uses it to find the display name that matches the current
field value. However, it also has to support a couple of edge cases. One of them is when
the field value is null and you have to call the inherited getter to properly handle format-
ting options for null values. The other is when the field value does not match any known
enum item and you, again, call the inherited getter, which converts it to string based on
the property's formatting options.
The PopulateListControl method uses the new keyword because this method is not
virtual in the base class, FieldTemplateUserControl . However, this should not be a
problem because the method will not be called polymorphically. Consistently with its
implementation in the base class, the PopulateListControl method also converts enum
values to their underlying integral equivalents for use in the list items. So instead of a
longer “ PartTime ”, the value of the enum item will be simply “ 1 ”. This reduces the size of
HTML and post-back data used by the page.
To take advantage of the new base class, you need to modify the Enumeration.ascx.cs and
the Enumeration_Edit.ascx.cs code-behind files that come with the enumeration field
templates out of the box so that they inherit from UnleashedEnumerationFieldTemplate
instead of the built-in FieldTemplateUserControl . Because PopulateListControl is a
direct replacement for the inherited method, no further changes are needed in the
Enumeration_Edit field template. It automatically starts showing the annotation-based
display names as illustrated in Figure 11.4.
FIGURE 11.4 Extended Enumeration_Edit Field template.
In addition to inheriting from the UnleashedEnumerationFieldTemplate base class, the
Enumeration field template also needs to be modified to use the overridden
FieldValueString instead of the EnumFieldValueString property that was defined in this
template out of the box. Markup of the modified version of the Enumeration field
template is shown in Listing 11.2.
Search WWH ::




Custom Search