Date format without time in ASP.NET Gridview

后端 未结 6 1287
Happy的楠姐
Happy的楠姐 2020-11-29 11:50

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



        
相关标签:
6条回答
  • 2020-11-29 12:34

    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}") %>' />
    
    0 讨论(0)
  • 2020-11-29 12:39

    Blockquote

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

    0 讨论(0)
  • 2020-11-29 12:46

    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**).

    0 讨论(0)
  • 2020-11-29 12:46

    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}") %>' />
    
    0 讨论(0)
  • 2020-11-29 12:51
    <asp:TemplateField HeaderText="Fromdate">    
         <ItemTemplate>    
               <asp:Label ID="lblFromdate" runat="server"
                     Text='<%#Eval("Fromdate", "{0:dd/MM/yyyy}") %>'></asp:Label>
          </ItemTemplate>
    </asp:TemplateField>
    
    0 讨论(0)
  • 2020-11-29 12:56

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

    It works well

    0 讨论(0)
提交回复
热议问题