C# VB.Net Formatting GridView Template Column Date Time or Number Numeric Field with Decimal Places in Asp.Net

In my previous Articles i have explained DateTime & Number DataType formatting of a GridView. In each cases I have considered GridView Bound Field or Column. But in this article I will demonstrate both DateTime & Number formatting for GridView Template Column.

Format GridView Template Column with DateTime Datatype:
Add a Template Column with textbox/label etc.. then format it in the below way:

<asp:TemplateField HeaderText="Recent Delivery">
<ItemTemplate><asp:Label ID="lbl" runat="server" Text='<%# Eval("LastDelivery", "{0:y}") %>'></asp:Label>
</ItemTemplate></asp:TemplateField>

Note: For detail formatting option CLICK HERE.

Sample Output for Short DateTime {0:y}:
dateformat1

Format GridView Template Column with Number Datatype:
Add a Template Column with textbox/label etc.. then format it in the below way:

<asp:TemplateField HeaderText="Recent Delivery">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%# Eval("Price", "{0:C2}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

Note: You may need to add few prefix like AU/US then use :
DataFormatString=”AU {0:C5}”
AUNumeric
OR
DataFormatString=”US {0:C5}”

Note: For more detail about Number Formatting CLICK HERE.

Posted in .Net, Asp.net, C#, Gridview, VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code
     
 

*