469,625 Members | 1,720 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

Need syntax help formatting a dateTime from a databinder.eval

I'm binding fileinformation to a repeater and attempting to display the
'lastWriteTime' property as a formatted date.

This:

<%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %>

Gives me the full date/time.

This:

<%# DataBinder.Eval(Container.DataItem, "{MM/DD/YYYY}" %>

Gives me a ' Overload resolution failed because no accessible 'ToString' can
be called without a narrowing conversion: '

Aha! It's not returning a dateTime value, but rather a string. Short of
parsing this string with regex or something, is there a way to get it to
return an actual dateTime value so I can use the format string on it?

-Darrel
Nov 19 '05 #1
4 10782
Hello darrel,

How about

DataBinder.Eval(Container.DataItem, "LastWriteTime", "{0:d}"

Look at http://msdn.microsoft.com/library/de...classtopic.asp
for information about the formatting patterns available.

For example: {0:F} is a FullDateTimePattern

--
Matt Berther
http://www.mattberther.com
I'm binding fileinformation to a repeater and attempting to display
the 'lastWriteTime' property as a formatted date.

This:

<%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %>

Gives me the full date/time.

This:

<%# DataBinder.Eval(Container.DataItem, "{MM/DD/YYYY}" %>

Gives me a ' Overload resolution failed because no accessible
'ToString' can be called without a narrowing conversion: '

Aha! It's not returning a dateTime value, but rather a string. Short
of parsing this string with regex or something, is there a way to get
it to return an actual dateTime value so I can use the format string
on it?

-Darrel


Nov 19 '05 #2
Darrel,

You should convert it ItemDataBound event in normal way, no regex is needed.

A c# example (assuming you are formatting column #2):

private void myGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
e.Item.Cells[2].Text=System.Convert.ToDateTime
(e.Item.Cells[2].Text).ToString(formatExpression);
}

Eliyahu

"darrel" <no*****@hotmail.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
I'm binding fileinformation to a repeater and attempting to display the
'lastWriteTime' property as a formatted date.

This:

<%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %>

Gives me the full date/time.

This:

<%# DataBinder.Eval(Container.DataItem, "{MM/DD/YYYY}" %>

Gives me a ' Overload resolution failed because no accessible 'ToString' can be called without a narrowing conversion: '

Aha! It's not returning a dateTime value, but rather a string. Short of
parsing this string with regex or something, is there a way to get it to
return an actual dateTime value so I can use the format string on it?

-Darrel

Nov 19 '05 #3
Matt,

As Darrel said, the column value comes as a string. Your reference is good
for DateTime values, not for strings.

Eliyahu

"Matt Berther" <mb******@hotmail.com> wrote in message
news:82***********************@news.microsoft.com. ..
Hello darrel,

How about

DataBinder.Eval(Container.DataItem, "LastWriteTime", "{0:d}"

Look at http://msdn.microsoft.com/library/de...classtopic.asp for information about the formatting patterns available.

For example: {0:F} is a FullDateTimePattern

--
Matt Berther
http://www.mattberther.com
I'm binding fileinformation to a repeater and attempting to display
the 'lastWriteTime' property as a formatted date.

This:

<%# DataBinder.Eval(Container.DataItem, "LastWriteTime" %>

Gives me the full date/time.

This:

<%# DataBinder.Eval(Container.DataItem, "{MM/DD/YYYY}" %>

Gives me a ' Overload resolution failed because no accessible
'ToString' can be called without a narrowing conversion: '

Aha! It's not returning a dateTime value, but rather a string. Short
of parsing this string with regex or something, is there a way to get
it to return an actual dateTime value so I can use the format string
on it?

-Darrel


Nov 19 '05 #4
Eliyahu and Matt:

Thank you both. Actually, I ended up getting it to work by casting from
string to date back to string with the format:

<%# ctype(DataBinder.Eval(Container.DataItem, "LastWriteTime"),
date).tostring("d") %>

It seems redundant to me, but seems to work!

-Darrel
Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Michelle Keys | last post: by
6 posts views Thread by Joe | last post: by
4 posts views Thread by Darrel | last post: by
2 posts views Thread by SimonZ | last post: by
5 posts views Thread by Stephen | last post: by
1 post views Thread by Vagabond Software | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.