Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
557 views
Welcome To Ask or Share your Answers For Others

1 Answer

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}") %>' />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...