Skip to main content
A newer version of this page is available. .
Tab

GridViewDataColumn.DataItemTemplate Property

Specifies a template to display the column’s data cells.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

NuGet Package: DevExpress.Web

Declaration

[DefaultValue(null)]
public virtual ITemplate DataItemTemplate { get; set; }

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.

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>

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;
    }
    

Online Example

View Example: ASPxGridView in batch edit mode - How to use and modify a control placed in DataItemTemplate

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

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.

See Also