473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 11347
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
6
by: Joe | last post by:
Hey, Can anyone out there see why when this code renders there's a 1px space between the headertemplate and the itemtemplate. <asp:datalist id="asplistDL" BorderStyle="None"...
5
by: Darren Smith | last post by:
Hi There, I have a shopping cart app that displays products along with a textbox (to enter quantity) and an image button to add the item to the shopping cart. Please explain why my below...
0
by: Anonieko Ramos | last post by:
Answer is in an article. > > > > Complex DataBinding with Date Formats in .NET 1.1 Did you know that you can do some pretty complex things with .NET's late binding in ASP.NET 1.X? I had a...
4
by: Darrel | last post by:
I'm stumped on something that would seem to be pretty simple. I have data bound to a repeater control. One of the fields is a date field from the SQL table: ...
2
by: TJ | last post by:
Why doesn't this work?\ string _s = String.Format("{0:M/d/yyyy}","5/20/2005 12:00:00 AM); Response.Write(_s); It kicks back the full date and time...I just want the date to show and not the...
2
by: SimonZ | last post by:
Hi, can someone explain me, when to use: (DateTime)DataBinder.Eval(Container.DataItem, "dateField") OR Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "dateField")) Sometimes...
5
by: Stephen | last post by:
Hi, Is there anyway I can make a column thats databound into a hyperlink to navigate to another page? Suppose I have 3 columns: SortOrder, Description, UserName for eg: <Columns>...
1
by: Vagabond Software | last post by:
I'm using a DropDownList in an EditItemTemplate column. This DropDownList will only ever have two dates in it; Now and the default DateTime value (1/1/1900 12:00:00 AM). Somewhere, somehow, the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.