1

I am calling one of the column dateadded in the datalist like:

<asp:Label ID="lblDate" runat="server" Text='<%# Eval("DateAdded") %>'></asp:Label>

On display it shows 24/04/2012 12:07:52 and i want to display : April 2012,

Can any one provide any assistance on how to get this display Thanks updated:

I trid this with no success:

<asp:Label ID="lblDate" runat="server" Text='<%# Eval("DateAdded").ToString("yyyyMM") %>'></asp:Label>

updated 2 [working]:

'<%# Eval("DateAdded" ,"{0:MMMM yyyy}") %>'>
4

2 に答える 2

2

You almost had it. Something like this should work:

Text='<%# Eval("DateAdded", "{0:MMMM yyyy}") %>'

The problem with your example is the Eval function returns type object, so it doesn't know how to apply the format. The Eval function overload (above) accepts a format and can figure all of that out behind-the-scenes, but you can also work around this by casting or converting the value to DateTime:

Text='<%# ((DateTime)Eval("DateAdded")).ToString("MMMM yyyy") %>'
于 2012-04-24T15:41:00.947 に答える
0

You can use this:

DateTime.Now.ToString("MMMM d, yyyy h:mm tt");
于 2020-07-27T03:42:23.143 に答える