GridView Format Field to Decimal Places

Posted: September 29, 2010 in ASP.Net

If you want to format a field as a currency field in a GridView, you can use the format mask {0:F2} which sets decimal places. For this example it sets the field to 2 decimal places:
ASP.Net (Design)

<asp:GridView id="grd_name" runat="server">
    <Columns>
        <asp:TemplateField HeaderText="Total Balance">
            <ItemTemplate>
                <asp:Label ID="lbl_total_balance" runat="server" Text='<%# Eval("total_balance", "{0:F2}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s