Databases Reference
In-Depth Information
. FieldValueEditString converts the field value to a string in Edit or Insert mode,
using the formatting options specified in the data model or page markup. It is an
equivalent of calling FormattingOptions.FormatEditField(FieldValue) .
During a post-back, a field template itself does not actually save the new column value
back in its Row object. Instead, the FieldTemplateUserControl class implements the
IBindableControl interface and relies on the parent FormView , DetailsView , and GridView
controls to perform this task. When the parent control is handling an Insert or an Update
command, it iterates through the list of its child controls and calls the ExtractValues of
each child that implements IBindableControl interface.
protected override void ExtractValues(IOrderedDictionary dictionary)
{
dictionary[this.Column.Name] =
this.ConvertEditedValue(this.textBox.Text);
}
The ExtractValues method receives a dictionary object used to store column name and
value pairs. The extract from the DateTime_Edit field template just shown is a typical
implementation of this method. The ConvertEditedValue method is provided by the
FieldTemplateUserControl base class. It can automatically convert the field value to null
based on the ConvertEmptyStringToNull and NullDisplayText formatting options.
Notice that by providing the dictionary argument, ExtractValue method allows a field
template to return values of other columns or even multiple column values. This capabil-
ity is important for the foreign key templates used for navigation properties, such as the
Customer property of the Order class in the Northwind data model, that need to return
values of the corresponding primitive properties, such as CustomerID. Consider Listing
3.9, which shows the markup of the ForeignKey_Edit template.
LISTING 3.9 ForeignKey_Edit Field Template (Markup)
<%@ Control Language=”C#” CodeBehind=”ForeignKey_Edit.ascx.cs”
Inherits=”WebApplication.DynamicData.FieldTemplates.ForeignKey_EditField” %>
<asp:DropDownList ID=”dropDownList” runat=”server”/>
<asp:RequiredFieldValidator runat=”server” ID=”requiredFieldValidator”
ControlToValidate=”dropDownList” Enabled=”false” />
<asp:DynamicValidator runat=”server” ID=”dynamicValidator”
ControlToValidate=”dropDownList” />
Notice that the ForeignKey_Edit template uses a DropDownList control, which allows
users to select from a list of items created programmatically, in the Page_Load method
shown in Listing 3.10. Each ListItem object in the DropDownList represents a single
foreign key, with Text property storing value of the display column from the referenced
Search WWH ::




Custom Search