aspnet-devexpress-dot-web-dot-gridviewdatacolumn-b88238f2.md
Specifies a template to display the column’s data cells.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
[DefaultValue(null)]
public virtual ITemplate DataItemTemplate { get; set; }
<DefaultValue(Nothing)>
Public Overridable Property DataItemTemplate As ITemplate
| Type | Default | Description |
|---|---|---|
| ITemplate | null |
An object that implements the ITemplate interface.
|
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.
Run Demo: ASPxGridView - Data Item Template
<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>
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.
Disable editing in the BatchEditStartEditing event handler.
View Example: How to access and modify a template control in batch edit mode
View Example: How to use an edit item and data item templates in batch mode
View Example: How to use the WebMethod attribute to update data in particular grid columns
View Example: How to enable or disable command buttons on the client
View Example: How to edit data in the grid with template checkboxes
View Example: How to use template editors to update grid data
View Example: Display an editor in a templated column based on another editor's value
View Example: How to calculate templated column values on the client
View Example: How to display a bar code image in a column
View Example: How to show a popup with an enlarged image on mouse hover
View Example: How to calculate bound and unbound column values on the client
View Example: How to implement the Select All functionality in a row
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DataItemTemplate property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
aspxgridview-dataitemtemplate-runtime/CS/HyperlinkColumn/Default.aspx.cs#L46
GridViewDataTextColumn colItemTemplate = new GridViewDataTextColumn();
colItemTemplate.DataItemTemplate = new MyHyperlinkTemplate(); // Create a template
colItemTemplate.Name = "colItemTemplate";
aspxgridview-dataitemtemplate-runtime/VB/HyperlinkColumn/Default.aspx.vb#L41
Dim colItemTemplate As GridViewDataTextColumn = New GridViewDataTextColumn()
colItemTemplate.DataItemTemplate = New MyHyperlinkTemplate() ' Create a template
colItemTemplate.Name = "colItemTemplate"
See Also