473,288 Members | 1,743 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,288 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 11332
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.