Skip to main content

MVCxGridViewColumn.SetDataItemTemplateContent(Action<GridViewDataItemTemplateContainer>) Method

Allows you to specify a template for data cells in the current column.

Namespace: DevExpress.Web.Mvc

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

NuGet Package: DevExpress.Web.Mvc5

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 for cells within an individual column.

@Html.DevExpress().GridView(settings =>
{
    settings.Name = "GridView";
    ...
    // Setting a template to render all the data cells within a "LastName" column
    settings.Columns.Add(column => {
        column.FieldName = "LastName";
        column.SetDataItemTemplateContent(cell => {
            ViewContext.Writer.Write("<b style=\"font-style:italic\">" + cell.Text + "</b>");
        });
    });
    settings.Columns.Add("FirstName");
    ...
}).Bind(Model).GetHtml()

The image below illustrates the result.

MVC_Grid_DataCells_TemplateOneColumn

Online Demos

Online Examples

View Example: How to display a hyperlink in a templated column

View Example: How to track changes of a checkbox editor's state

View Example: How to use template editors to update grid data

View Example: How to Open a Popup Window on a Hyperlink Click

See Also