1

Possible Duplicate:
Format Date in Bind Statement inside a ListView

I have modified a master detail gridview example as per my requirement. It is working fine but date format in one of cell is displaying as "12/12/2012 12:00:00 AM". I just want to show only "12/12/2012". Please help, code is as below"

<asp:TemplateField HeaderText="Date of Failure" SortExpression="Failure_date" >
<EditItemTemplate>
<asp:TextBox ID="EditFailure_date" runat="server" Columns="20" MaxLength="50" Text='<%# Bind("Failure_date") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="Failure_dateRequiredFieldValidator" runat="server" ControlToValidate="EditFailure_date" Display="Dynamic"  ErrorMessage="Can not be blank" SetFocusOnError="True"></asp:RequiredFieldValidator>
 </EditItemTemplate>
 <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" />
 <HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" />
 <ItemTemplate>
 <asp:Label ID="Failure_date" runat="server"  Text='<%# Bind("Failure_date") %>' ></asp:Label>
 </ItemTemplate>
 </asp:TemplateField>  
Community
  • 1
  • 1
user1185088
  • 99
  • 1
  • 1
  • 8

2 Answers2

5

This is the format that you should use:

<%# Bind("Failure_date", "{0:dd/MM/yyyy}") %>
matt1125
  • 3
  • 3
Richard
  • 21,728
  • 13
  • 62
  • 101
2

You can do it by passing the format to the 2 Bind parameter.

Text='<%# Bind("Failure_date","{0:dd/MM/yyyy}") %>'
Emad Mokhtar
  • 3,237
  • 5
  • 31
  • 49