Skip to main content

GridViewSettings.SetDataItemTemplateContent(Action<GridViewDataItemTemplateContainer>) Method

Allows you to specify a data cell template.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v24.2.dll

Declaration

public void SetDataItemTemplateContent(
    Action<GridViewDataItemTemplateContainer> contentMethod
)

Parameters

Name Type Description
contentMethod Action<GridViewDataItemTemplateContainer>

A method to which a template content rendering is delegated.

Remarks

Note

Once a template defined using the SetDataItemTemplateContent method is created, it is instantiated within a container object of the GridViewDataItemTemplateContainer type. This container object exposes a set of members which can be useful when designing a template.

The code sample below demonstrates how to define the template common to all the grid data cells.

@Html.DevExpress().GridView(settings =>
{
    settings.Name = "GridView";
    ...
    // Setting a template to render all the data cells within a Grid
    settings.SetDataItemTemplateContent(cell => {
        ViewContext.Writer.Write("<span style=\"color:red\">" + cell.Text + "</span>");
    });

    settings.Columns.Add("LastName");
    settings.Columns.Add("FirstName");
    ...
}).Bind(Model).GetHtml()

The image below illustrates the result.

MVC_Grid_DataCells_TemplateEntireGrid

Note

Batch Edit Mode Limitations

When adding new rows in Batch Editing mode, only a light (client HTML hierarchy) copy of the server MVC extensions in the template defined via the GridViewSettings.SetDataItemTemplateContent(Action`1) method is created. Since there is no callback to the server, MVC Extensions cannot be initialized completely according to the logic defined on the server. In other words, the server-side code that adjusts the extension settings is not triggered. Therefore, the resulting UI might not operate as expected.

See Also