Databases Reference
In-Depth Information
As you can see, very few changes were required in the Region field template to support
dynamic interaction with the country property. In fact, it is similar to the initial imple-
mentation created in Chapter 10, where the name of the country property was hard-
coded. With the knowledge of the property name extracted outside of the field template,
it is now generic enough to support any region property in the Northwind entity model
and could be reused on other projects.
Fixing the FindOtherFieldTemplate Method
Unfortunately, the FindOtherFieldTemplate method provided by Dynamic Data does not
work in the dynamically populated FormView and GridView controls and simply returns
null . It is possible that this method was created for the initial release of Dynamic Data in
service pack 1 of the .NET Framework 3.5 and has not been updated to work with the
entity templates introduced in version 4.0. As a workaround, this method was reimple-
mented in the UnleashedFieldTemplate base class. Listing 11.10 shows a partial listing of
the class, with just the code relevant to the current discussion.
LISTING 11.10 FindOtherFieldTemplate Method in UnleashedFieldTemplate
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Web.DynamicData;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Unleashed.DynamicData
{
public partial class UnleashedFieldTemplate : FieldTemplateUserControl
{
protected new UnleashedFieldTemplate FindOtherFieldTemplate(string columnName)
{
var template = (UnleashedFieldTemplate)
base.FindOtherFieldTemplate(columnName);
if (template == null && !string.IsNullOrEmpty(columnName))
{
Control parent = this.FindParentOfAllFieldTemplates();
template = (UnleashedFieldTemplate)
FindControlRecursively(parent, “__” + columnName);
}
return template;
}
private Control FindParentOfAllFieldTemplates()
 
Search WWH ::




Custom Search