Skip to main content

ASPxPivotGrid.FieldValueTemplate Property

Gets or sets a template to display the content of field value cells.

Namespace: DevExpress.Web.ASPxPivotGrid

Assembly: DevExpress.Web.ASPxPivotGrid.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

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

Property Value

Type Default Description
ITemplate null

An object supporting the System.Web.UI.ITemplate interface that contains the custom content for field value cells.

Remarks

By creating a template of the FieldValueTemplate type, you can define the custom content displayed for field value cells in the ASPxPivotGrid control. The field value appearance can be controlled by the PivotGridStyles.FieldValueStyle or PivotGridField.ValueStyle property.

The content of values that correspond to a particular field can be specified using the field’s PivotGridField.ValueTemplate property. This property takes precedence over the FieldValueTemplate property.

Note

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

Example

This example demonstrates how to customize the Field Header and Field Value templates, and keep automatic appearance and functionality. It is not possible to simply replace the default Header or Value element with a custom label, because these elements have a really complex layout. Ordinarily, it consists of a table including a few cells with nested items, and attached styles and scripts. These elements are generated dynamically based on the current pivot grid layout. This example demonstrates how to customize the templates at runtime. Using this approach, it is possible to call the PivotGridFieldValueTemplateContainer.CreateFieldValue and PivotGridHeaderTemplateContainer.CreateHeader methods to generate the default template content. Then it is possible to replace some of default items with custom ones to introduce a required functionality.

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxPivotGrid;

namespace E1805 {
    public partial class _Default :System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            ASPxPivotGrid1.HeaderTemplate = new HeaderTemplate();
            ASPxPivotGrid1.FieldValueTemplate = new FieldValueTemplate();
        }
    }

    public class HeaderTemplate :ITemplate {
        public void InstantiateIn(Control container) {
            PivotGridHeaderTemplateContainer c = (PivotGridHeaderTemplateContainer)container;
            PivotGridHeaderHtmlTable table = c.CreateHeader();
            table.Content = new HeaderLink();
            c.Controls.Add(table);
        }
    }

    class FieldValueTemplate :ITemplate {
        public void InstantiateIn(Control container) {
            PivotGridFieldValueTemplateContainer c = (PivotGridFieldValueTemplateContainer)container;
            PivotGridFieldValueHtmlCell cell = c.CreateFieldValue();
            cell.Controls.AddAt(cell.Controls.IndexOf(cell.TextControl), new HeaderLink());
            cell.Controls.Remove(cell.TextControl);
            c.Controls.Add(cell);
        }
    }

    public class HeaderLink :HyperLink {
        public HeaderLink()
            : base() {
            Text = "Templated Text";
            NavigateUrl = "#";
            Attributes["onclick"] = "alert('this is the test prompt')";
        }
    }
}
See Also