Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Saturday, 7 February 2015

Introduction: 
Some time we want to show date in particular format in gridview. In order to format DateTime field in GridView’s ItemTemplate we have to pass format in Eval  . There are many format available for the DateTime  and  here i have given some example that demonstrate how to format DateTime .


If you are using ItemTemplate   to show Date of birth field in GridView then: 

<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID="lblDOB" runat="server" Text='<%# Eval("Date", "{0:dd/MM/yyyy}")%>' ></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

OR


<asp:TemplateField>
    <ItemTemplate>
        <asp:Label ID=" lblDOB " runat="server" Text='<%# Eval("Date", "{0:D}")%>' ></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
  • If you are using BoundField  to show Date of birth field in gridview then: .

<asp:BoundField DataField="DOB" DataFormatString="{0:d}" HeaderText="Date of birth" />


Available Date formats, that we can use to format date in gridview columns as per requirement.


Format Pattern
Name
Result Example
d
Short date
11/8/2008
D
Long date
Sunday, August 11, 2008
t
Short time
3:32 PM
T
Long time
3:32:00 PM
f
Full date/time (short time)
Sunday, August 11, 2008 3:32 PM
F
Full date/time (long time)
Sunday, August 11, 2008 3:32:00 PM
g
General date/time (short time)
8/11/2008 3:32 PM
G
General date/time (long time)
8/11/2008 3:32:00 PM
m or M
Month day
August 11
r or R
RFC 1123
Sun, 11 Aug 2008 8:32:00 GMT
s
Sortable date/time
2008-08-11T15:32:00
u
Universable sortable date/time
2008-08-11 15:32:00z
U
Universable sortable date/time
Sunday, August 11, 2008 11:32:00 PM
y or Y
Year month
August, 2008
Categories: ,

0 comments:

Post a Comment