DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Format Data Shown In Grid View With Template Field

  • submit to reddit
        Add following to your grid view.

<asp:TemplateField HeaderText="Birth Date"> <ItemTemplate>
<asp:TextBox runat="server" ID="Txt_Birth_Date" Width="60%" Text='<%# DataBinder.Eval (Container.DataItem, "Birth", "{0:d}") %>' />
  </ItemTemplate> </asp:TemplateField>

Following are some other format change pattern of date
Left hand side is Format= Right hand side is Description
d = ShortDatePattern
T = LongTimePattern
u = UniversalSortableDateTimePattern using the format for universal time display
U = Full date and time (long date and long time) using universal time
y, Y = YearMonthPattern
G = General (short date and long time)
m, M = MonthDayPattern
r, R = RFC1123Pattern
s = SortableDateTimePattern (based on ISO 8601) using local time
t = ShortTimePattern
D = LongDatePattern
f = Full date and time (long date and short time)
F = FullDateTimePattern (long date and long time)
g = General (short date and short time)