Data Formatting String – ASP.NET

There are many format strings available to format your data in desired format.

I found it easy to have a list of all applicable format strings at one place so I can apply without looking around searching what is going to fit best according to the requirement. I have compiled a list of formatting strings that work with ASP.NET GridView. Hope you find this table helpful.

Format String



Number Format


Local Currency Format



Local Currency Format without decimal points



Local Currency Format with 4(four) decimal points



Integer Number only



Integer Number of 8 digits (if unavailable the padded with leading zero)



Scientific Format



Fixed Number format



Fixed Number format with 4 decimal places



Number format with thousand separator



Number format with Percentage



Hexadecimal format (Integer only)


Date Format


Small Date



Long Date

Thursday, March 11, 2004


Long Date, Small Time

Thursday, March 11, 2004 10:01 AM


Long Date, Long Time

Thursday, March 11, 2004 10:01:36 AM


Small Date, Small Time

3/11/2004 10:01 AM


Small Date, Long Time

3/11/2004 10:01:36 AM

{0:m} or {0:M}

Month Date

March 11


Small Time

10:01 AM


Long Time

10:01:36 AM


Universal long date and long time

Thursday, March 11, 2004 3:01:36 PM

{0:y} or {0:Y}

Month Year

March, 2004


I used GridView with Bound field and Sql Data Source with connection to Adventure works database to test all these settings:


<html xmlns="">

<head runat="server">




<form id="form1" runat="server">



<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataKeyNames="ProductID" DataSourceID="SqlDataSource1"

EmptyDataText="There are no data records to display.">


<asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="True"

SortExpression="ProductID" DataFormatString="{0:x}" />

<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

<asp:BoundField DataField="StandardCost" HeaderText="StandardCost"

SortExpression="StandardCost" DataFormatString="{0:P0}" />

<asp:BoundField DataField="ProductNumber" HeaderText="ProductNumber"

SortExpression="ProductNumber" />

<asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate"

SortExpression="ModifiedDate" DataFormatString="{0:y}" />



<asp:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:ConnStr %>"

ProviderName="<%$ ConnectionStrings:ConnStr.ProviderName %>"

SelectCommand="SELECT [ProductID], [Name], [StandardCost], [ProductNumber],ModifiedDate FROM [Product]"