SolutionCottage.com
Posted  19 Nov 2008 - 19:50:28

Category: ASP.net


Format bound templatefield to other date format

Issue:
You have a Data control of some sort that is databound. In the Grid you might have asp:Labels that get their value from a datasource via Bind("variable") or something similar. You probably store this in a database in format DateTime. The problem is you want this in a different format.

Solution:
Use the Convert.ToDateTime function. Here is an example:

<asp:Label ID="DateLabel" runat="server" Text='<%# Convert.ToDateTime(Eval("Date")).ToString("dd MMM yyyy - HH:mm:ss") %>' />


You can find a good source for the date formats here:

system.globalization.datetimeformatinfo



Marked as helpful by 1 user




2 comments:

7/18/2012 9:54:57 AM  s  wrote:

s


5/17/2011 4:51:14 PM  this  wrote:

not working for sorting column









© SolutionCottage 2008-2011 9/26/2017 9:58:57 AM