Vineeth S
Vineeth S

Reputation: 301

Date format without time in ASP.NET Gridview

in ASP.NET gridview binding two dates. I want to display dd/MM/yyyy but it displays 10/03/2014 00:00:00.

<asp:TemplateField HeaderText ="Fromdate" >
   <ItemTemplate >
   <asp:Label ID="lblFromDate" runat="server" 
              DataFormatString="{0:dd/MM/yyyy}" 
              HtmlEncode="false"  
              Text='<%# Eval("Fromdate") %>' />
    </ItemTemplate>
</asp:TemplateField>

Upvotes: 18

Views: 82882

Answers (6)

Shahbaz Raees2
Shahbaz Raees2

Reputation: 221

Blockquote

Eval("Date","{0:dd-MM-yyyy}") %>' />

Upvotes: 0

IUnknown
IUnknown

Reputation: 22448

DataFormatString is a property of BoundField control and doesn't affect any other control. You can specify the format in an Eval expression:

Text='<%# Eval("Fromdate", "{0:dd/MM/yyyy}") %>' />

Upvotes: 25

shafi7468
shafi7468

Reputation: 433

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

Upvotes: 2

VSaavedra
VSaavedra

Reputation: 81

I achieved it with {0:dd/MM/yyyy} on the DataFormatString property of the field

It works well

Upvotes: 8

M.A.G
M.A.G

Reputation: 41

DataFormatString is a property of BoundField control and doesn't affect any other control. You can specify the format right in the Eval expression:

Text='<%# Eval("Fromdate", "{0:dd/MM/yyyy}") %>' />

Upvotes: 4

nestedloop
nestedloop

Reputation: 2646

According to this article on MSDN the DataFormatString attribute has a limited number of variants for DateTime data.

What you are looking for is:

DataFormatString="{0:d}"

which is the short date pattern.

In order to get the dd/MM/yyyy format, you need to also set your culture info properly (for example to **en-GB**).

Upvotes: 21

Related Questions