Question

How can I format to currency the value of a column in my gridview ?

I tryied the following code, but doesn't work, still unformatted.

<asp:GridView ID="grdDetalhePropostaExpirada" Width="100%" runat="server" AutoGenerateColumns="false" DataSourceID="dsGridExpira">        
    <Columns>
        <asp:BoundField HeaderText="Valor" DataField="ValorProposta" DataFormatString="{0:c}" />
    </Columns>
</asp:GridView>
Was it helpful?

Solution

You have to set your HTMLEncode to False:

<Columns>
    <asp:BoundField HeaderText="Valor" DataField="ValorProposta" HtmlEncode="False" DataFormatString="{0:c}" />
</Columns>

MSDN: In versions of ASP.NET earlier than 3.5, you must set the HtmlEncode property to false in order to format fields that are not string data types. Otherwise, the field value is converted to a string by the default conversion method before the format string that is stored in the DataFormatString property is applied.

OTHER TIPS

You can try setting the DataFormatString="{0:$#,##0.00;($#,##0.00);0}" and setting the HTMLEncoded = false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top