A newer version of this page is available. Switch to the current version.

GridViewSettings.SetDataItemTemplateContent(Action<GridViewDataItemTemplateContainer>) Method

Allows setting a template for displaying data cells.

Namespace: DevExpress.Web.Mvc

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

Declaration

public void SetDataItemTemplateContent(
    Action<GridViewDataItemTemplateContainer> contentMethod
)
Public Sub SetDataItemTemplateContent(
    contentMethod As Action(Of GridViewDataItemTemplateContainer)
)

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