472,362 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,362 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 11115
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.