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

GridViewDataColumn.DataItemTemplate Property

Gets or sets a template for displaying data cells within the current column.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.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

To provide a common template for displaying data cells within the ASPxGridView, use the GridViewTemplates.DataItem property.

Note

Once a template defined via the DataItemTemplate property is created within a control, it is instantiated within a container object of the GridViewDataItemTemplateContainer type. This container object exposes a set of specific properties to which the template’s child controls can be bound.

If to create a new row in Batch Edit Mode when a column implements a DataItemTemplate, only HTML markup of the row is copied. So, it is recommended to use the DataItemTemplate in Batch Edit mode only for appearance customization.

Online Example

Example

Custom logic implemented in this example allows the end-user to select a limited number of named columns via comboboxes. The maximum number of columns the user can select is defined by a numeric column value, which he can also change. The only callback is used to post the entire grid page data. To work in multi-row-edit mode, scripts and ClientInstanceName property values are generated programmatically.

GridView_DataItemTemplate

View Example

public void InstantiateIn(Control container)
{
    GridViewDataItemTemplateContainer gcontainer = (GridViewDataItemTemplateContainer)container;
    ASPxComboBox cbx = new ASPxComboBox();
    cbx.ID = "cbx_" + gcontainer.Column.FieldName;
    cbx.ValueType = typeof(bool);
    cbx.Items.Add("Yes", true);
    cbx.Items.Add("Blank", false);
    string code = DataBinder.Eval(gcontainer.DataItem, "Code") as string;
    bool value = string.IsNullOrEmpty(code) ? false : code.Contains(gcontainer.Column.FieldName);
    cbx.Value = value;
    cbx.Width = Unit.Pixel(80);
    int num = Convert.ToInt32(DataBinder.Eval(gcontainer.DataItem, "Num"));
    cbx.ClientEnabled = value || code.Length < num;
    cbx.ClientSideEvents.SelectedIndexChanged = "function(s,e){RefreshRow("+gcontainer.VisibleIndex+");}";
    cbx.ClientInstanceName = "cbx_" + gcontainer.Column.FieldName + gcontainer.VisibleIndex.ToString();
    gcontainer.Controls.Add(cbx);
}

The following code snippets (auto-collected from DevExpress Examples) contain references 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