Databases Reference
In-Depth Information
LISTING 11.10
Continued
{
Control parent = this.Parent;
while (parent != null)
{
if (parent is GridViewRow ||
parent is FormViewRow ||
parent is DetailsViewRow)
break;
parent = parent.Parent;
}
return parent;
}
private static Control FindControlRecursively(Control parent, string id)
{
Control control = parent.FindControl(id);
if (control != null)
return control;
foreach (Control child in parent.Controls)
{
control = FindControlRecursively(child, id);
if (control != null &&
0 == string.Compare(control.ID, id, StringComparison.OrdinalIgnoreCase))
return control;
}
return null;
}
}
The reimplemented
FindOtherFieldTemplate
method first tries to call the inherited
version, which succeeds if this field template was created in a custom page and the built-
in logic was sufficient to find the template. If the template was not found, the
FindOtherFieldTemplate
first locates the ultimate parent of all field templates of the
current entity. It does that by calling the
FindParentOfAllFieldTemplates
method, which
walks up the parent chain until it finds a known container, which could be a
GridViewRow
, a
FormViewRow
, or a
DetailsViewRow
, depending on the type of control used
to create the UI—a
GridView
, a
FormView
, or a
DetailsView
, respectively. Having located
the ultimate parent, the
FindOtherFieldTemplate
calls the
FindControlRecursively
method, which traverses the hierarchy of controls recursively until it finds the target field
template.