Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
At time of Label binding with datavale in Template feild of Gridview How to set Date format
Posted

Hi,
Here is an example:
XML
<ItemTemplate>

<asp:TextBox id="txtCloseDate" Text='<%# Eval("CloseDate","{0:dd/MM/yy}") %>' runat="server" />

</ItemTemplate>



You can format it using a method in your code behind too:
XML
<ItemTemplate>
<asp:Label

ID="BeginDateLabel"
runat="server"

Width="80px"

Text='<%# DateFormatter((DateTime)Eval("BeginDate")) %>'>

</asp:Label>

</ItemTemplate>

in your codebehind:
protected string DateFormatter(DateTime date)

{
return date.ToShortDateString();

}



I hope it will help,
Cheers.
 
Share this answer
 
v2
try:
ASP.NET
<ItemTemplate><asp:Label ID="lblDOB" runat="server" Text='<%# Eval("DOB","{0:d}") %>'></ItemTemplate></asp:TemplateField>

for more refer:
http://www.bloggerindia.in/date-format-in-gridview-using-asp-net-2-0/[^]
http://gridview-date-format.blogspot.in/[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900