Search code examples
asp.netdata-bindingservercontrols

Why is my derived server control rendering its DataFormatString instead of a formatted data value?


I have the control below derived from a BoundField, used inside a GridView, as in the markup below the code. My problem is that the control renders the literal value of it's DataFormatString, not a formatted representation of it's data value.

public class BoundReportField : BoundField
{
    public override string DataFormatString
    {
        get
        {
            var baseString = base.DataFormatString;
            if (!string.IsNullOrWhiteSpace(baseString))
            {
                return FormatStrings.Currency;
            }
            return baseString;
        }
        set
        {
            base.DataFormatString = value;
        }
    }

    protected override string FormatDataValue(object dataValue, bool encode)
    {
        var val = base.FormatDataValue(dataValue, encode);
        return val;
    }
}

<avm:BoundReportField DataField="BOND_AMOUNT" DataFormatString="R #\,###\,###" />

Solution

  • Try doing this in your markup:

    DataFormatString="{0:R #\,###\,###}"
    

    EDIT
    Removed extra quote