Phillip Schmidt
Phillip Schmidt

Reputation: 8818

DevExpress Pivot Grid not accepting format string

I have a DevExpress PivotGrid in my site that grabs a bunch of numbers from a sql view. I'd like to format them to 2 decimal places. I've tried the following:

<dx:pivotgridfield id="AverageDailySales" visible="True"
 fieldname="AvgDailySales" CellFormat-FormatString="(0:n2}" Options-AllowFilter="True"></dx:pivotgridfield>

And in the page_load:

AverageDailySales.CellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
AverageDailySales.CellFormat.FormatString = "{0:n2}"
AverageDailySales.GrandTotalCellFormat.FormatType = DevExpress.Utils.FormatType.Numeric
AverageDailySales.GrandTotalCellFormat.FormatString = "{0:n2}"

But it's still not formatting to two places. When I put it as a data field (and I get a grand total column for it), it works. Otherwise it doesn't. Any idea what I'm doing wrong?

Upvotes: 1

Views: 4386

Answers (1)

tlbignerd
tlbignerd

Reputation: 1114

I believe your format string is incorrect, it should not include the 0 identifier. This should be:

<dx:pivotgridfield id="AverageDailySales" visible="True"
 fieldname="AvgDailySales" CellFormat-FormatString="n2" Options-AllowFilter="True"></dx:pivotgridfield>

Typically the format fields in DevExpress look just for the format to use, and assume there is only a single value to format. I'm also basing this on the DevExpress How to: Format Cells documentation.

Upvotes: 1

Related Questions