ASPxPivotGrid.FieldValueTemplate Property
Namespace: DevExpress.Web.ASPxPivotGrid
Assembly:
DevExpress.Web.ASPxPivotGrid.v24.1.dll
NuGet Package:
DevExpress.Web
Declaration
[DefaultValue(null)]
public virtual ITemplate FieldValueTemplate { get; set; }
<DefaultValue(Nothing)>
Public Overridable Property FieldValueTemplate As ITemplate
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.
|
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')";
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="E1805._Default" %>
<%@ Register assembly="DevExpress.Web.ASPxPivotGrid.v9.2, Version=9.2.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPivotGrid" tagprefix="dxwpg" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxwpg:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server"
DataSourceID="AccessDataSource1">
<Fields>
<dxwpg:PivotGridField ID="fieldSalesPerson" Area="RowArea" AreaIndex="0"
FieldName="Sales_Person">
</dxwpg:PivotGridField>
<dxwpg:PivotGridField ID="fieldExtendedPrice" Area="DataArea" AreaIndex="0"
FieldName="Extended_Price">
</dxwpg:PivotGridField>
<dxwpg:PivotGridField ID="fieldCategoryName" Area="ColumnArea" AreaIndex="0"
FieldName="CategoryName">
</dxwpg:PivotGridField>
</Fields>
</dxwpg:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [Sales Person] AS Sales_Person, [Extended Price] AS Extended_Price, [CategoryName] FROM [SalesPerson]">
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxPivotGrid
Namespace E1805
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ASPxPivotGrid1.HeaderTemplate = New HeaderTemplate()
ASPxPivotGrid1.FieldValueTemplate = New FieldValueTemplate()
End Sub
End Class
Public Class HeaderTemplate
Implements ITemplate
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim c As PivotGridHeaderTemplateContainer = CType(container, PivotGridHeaderTemplateContainer)
Dim table As PivotGridHeaderHtmlTable = c.CreateHeader()
table.Content = New HeaderLink()
c.Controls.Add(table)
End Sub
End Class
Friend Class FieldValueTemplate
Implements ITemplate
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim c As PivotGridFieldValueTemplateContainer = CType(container, PivotGridFieldValueTemplateContainer)
Dim cell As PivotGridFieldValueHtmlCell = c.CreateFieldValue()
cell.Controls.AddAt(cell.Controls.IndexOf(cell.TextControl), New HeaderLink())
cell.Controls.Remove(cell.TextControl)
c.Controls.Add(cell)
End Sub
End Class
Public Class HeaderLink
Inherits HyperLink
Public Sub New()
MyBase.New()
Text = "Templated Text"
NavigateUrl = "#"
Attributes("onclick") = "alert('this is the test prompt')"
End Sub
End Class
End Namespace
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="E1805._Default" %>
<%@ Register assembly="DevExpress.Web.ASPxPivotGrid.v9.2, Version=9.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPivotGrid" tagprefix="dxwpg" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxwpg:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server"
DataSourceID="AccessDataSource1">
<Fields>
<dxwpg:PivotGridField ID="fieldSalesPerson" Area="RowArea" AreaIndex="0"
FieldName="Sales_Person">
</dxwpg:PivotGridField>
<dxwpg:PivotGridField ID="fieldExtendedPrice" Area="DataArea" AreaIndex="0"
FieldName="Extended_Price">
</dxwpg:PivotGridField>
<dxwpg:PivotGridField ID="fieldCategoryName" Area="ColumnArea" AreaIndex="0"
FieldName="CategoryName">
</dxwpg:PivotGridField>
</Fields>
</dxwpg:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/nwind.mdb"
SelectCommand="SELECT [Sales Person] AS Sales_Person, [Extended Price] AS Extended_Price, [CategoryName] FROM [SalesPerson]">
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
See Also