GridViewDataColumn.DataItemTemplate Property
Specifies a template to display the column’s data cells.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v22.2.dll
NuGet Package: DevExpress.Web
Declaration
Property Value
Type | Default | Description |
---|---|---|
ITemplate | null | An object that implements the ITemplate interface. |
Remarks
When you specify the DataItemTemplate
property, the control creates a template within a container object of the GridViewDataItemTemplateContainer type.
At the control level, use the GridView.Templates.DataItem property to specify a template for all grid data cells.
<dx:ASPxGridView ID="grid" runat="server" AutoGenerateColumns="false" ...>
<Columns>
<!-- ... -->
<dx:GridViewDataColumn Caption="Details" ...>
<DataItemTemplate>
<a href="javascript:void(0);"
onclick="OnMoreInfoClick(this, '<%# Container.KeyValue %>')">More Info...</a>
</DataItemTemplate>
</dx:GridViewDataColumn>
</Columns>
</dx:ASPxGridView>
Batch Edit Mode Specifics
In batch edit mode, ASPxGridView copies only HTML markup of the template and disables its client-side functionality. When a cell switches to edit mode, the grid invokes an in-place editor to modify grid data. When editing ends, the grid displays the entered value in the modified cell.
You can change this behavior in the following ways:
- Allow the grid to render the template content after cell editing ends
To enable this behavior, set the AllowRegularDataItemTemplate property to
true
.<dx:ASPxGridView ID="Grid" runat="server" ..."> <Columns> <dx:GridViewDataTextColumn FieldName="TemplatedColumn" /> <DataItemTemplate> <!-- ... --> </DataItemTemplate> </dx:GridViewDataColumn> </Columns> <SettingsEditing Mode="Batch"> <BatchEditSettings AllowRegularDataItemTemplate="true" /> </SettingsEditing> </dx:ASPxGridView>
- Disable cell editing
When you disable a cell editing, the grid displays the template content and keeps its client-side functionality. To enable this behavior, use one of the following approaches:
Set the templated column’s EditFormSettings.Visible property to
false
.<dx:GridViewDataTextColumn FieldName="TemplatedColumn" /> <DataItemTemplate> <!-- ... --> </DataItemTemplate> <EditFormSettings Visible="False" /> </dx:GridViewDataColumn>
Disable editing in the BatchEditStartEditing event handler.
<dx:ASPxGridView ID="Grid" runat="server" ...> <!-- ... --> <ClientSideEvents BatchEditStartEditing="StartEditing" /> </dx:ASPxGridView>
function StartEditing(s, e) { if (e.focusedColumn.fieldName === "TemplatedColumn") e.cancel = true; }