Databases Reference
In-Depth Information
field.HeaderText = column.ShortDisplayName;
else
field.HeaderText = column.Prompt ?? column.DisplayName;
field.ItemStyle.Wrap = false;
return field;
}
}
}
The
UnleashedFieldGenerator
provides a parameterized constructor, which is required to
specify the
MetaTable
object when the generator is created. It also overrides the
CreateField
method to create and initialize a new instance of the
UnleashedField
control. In particular, it sets the
HeaderText
property of the new field using different
values from the column metadata, depending on the context where the new field will be
used. If
List
value was passed as the
containerType
, it means that the field will appear in
a
GridView
control and the short version of column's display name is used as the header.
Otherwise, if
Item
container type was specified, the field will appear in a
DetailsView
control and the
prompt
(if it was specified) or the full display name of the column will be
displayed in the label. Finally, wrapping is turned off to prevent validators from appearing
on the next line if an error needs to be reported by the field template.
With the
UnleashedFieldGenerator
class, you still have to modify the
List
and
ListDetails
page templates to use it. In custom pages, where you initialize the
ColumnsGenerator
property of
GridView
control explicitly, you can simply change the
code to instantiate the
UnleashedFieldGenerator
explicitly. However, in the dynamic
page templates that come with the Dynamic Data project in Visual Studio, the
DefaultAutoFieldGenerator
is created by the
DynamicDataManager
during the
InitComplete
event of the
Page
. To replace this logic, you can create your own
Page.InitComplete
event handler as shown in this code snippet:
public partial class List : System.Web.UI.Page
{
protected MetaTable table;
protected void Page_InitComplete(object sender, EventArgs e)
{
this.gridView.ColumnsGenerator = new UnleashedFieldGenerator(this.table);
}
}
Because the
Page_InitComplete
method runs after the event handler the
DynamicDataManager
uses to initialize the
ColumnsGenerator
property of the
GridView
, this
code replaces it with the
UnleashedFieldGenerator
. As a result, the
GridView
will be
populated with
UnleashedField
instances that have full support for metadata-driven
control parameters, and the Address text box, for which the
Columns
parameter was speci-
fied in metadata of the Employee entity, will now be wide enough to support longer
address values.