Databases Reference
In-Depth Information
LISTING 11.7
UnleashedField Implementation
using System.Web.DynamicData;
namespace Unleashed.DynamicData
{
public class UnleashedField : DynamicField
{
protected override DynamicControl CreateDynamicControl()
{
return new UnleashedControl();
}
}
}
Extending DefaultAutoFieldGenerator to Support Control Parameters
With the
UnleashedField
class, you can fix the problem in the custom
GridView
page
from Listing 11.6 by simply replacing the
DynamicField
instances with the extended
controls. However, solving the problem in the
dynamic
page templates is a little more
involved. As you recall from discussions in Chapter 6, “Page Templates,” a special
Dynamic Data class,
DefaultAutoFieldGenerator
, is responsible for automatically generat-
ing the
DynamicField
instances for
GridView
and
DetailsView
controls based on a
MetaTable
object associated with it. Because the
DefaultAutoFieldGenerator
creates the
DynamicField
instances, you also need to extend it to have the
UnleashedField
instances
created in dynamic page templates instead. Listing 11.8 shows the
UnleashedFieldGenerator
class, also available in the sample solution.
LISTING 11.8
UnleashedFieldGenerator Implementation
using System.Web.DynamicData;
using System.Web.UI.WebControls;
namespace Unleashed.DynamicData
{
public class UnleashedFieldGenerator: DefaultAutoFieldGenerator
{
public UnleashedFieldGenerator(MetaTable table): base(table)
{
}
protected override DynamicField CreateField(MetaColumn column,
ContainerType containerType, DataBoundControlMode mode)
{
var field = new UnleashedField();
field.DataField = column.Name;
if (containerType == ContainerType.List)