Wednesday, March 28, 2012

String was not recognized as a valid DateTime

I moved some projects to another server and using the code below i get
the error:-

"String was not recognized as a valid DateTime"

<asp:Label runat="server" width="40%" text='
<%#
DateTime.Parse(DataBinder.Eval(Container,"DataItem.dt").ToString()).ToSh
ortDateString()%>' id="Label6"
*** Sent via Developersdex http://www.developersdex.com ***Well folks...
I added:-
culture="en-US"
to the globalization in Web.Config and did the trick

<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-US"
/
*** Sent via Developersdex http://www.developersdex.com ***
Hi Patrick,

If you just use DataBinder.Eval(Container,"DataItem.dt").ToString() is
anything displayed?

If it is, I would be checking that the date format matches your Regional
Settings (System Account). If you are using SQL I'd also be checking that
the collation of the new server/database is the same as your old one.

Brad.

"Patrick Olurotimi Ige" wrote:

> I moved some projects to another server and using the code below i get
> the error:-
> "String was not recognized as a valid DateTime"
> <asp:Label runat="server" width="40%" text='
> <%#
> DateTime.Parse(DataBinder.Eval(Container,"DataItem.dt").ToString()).ToSh
> ortDateString()%>' id="Label6">
>
> *** Sent via Developersdex http://www.developersdex.com ***
> <asp:Label runat="server" width="40%" text='
> <%#
> DateTime.Parse(DataBinder.Eval(Container,"DataItem.dt").ToString()).To
> Sh
> ortDateString()%>' id="Label6"
Why don't you just do this instead:

<%# ((DateTime)DataBinder.Eval(Container.DataItem, "dt")).ToShortDateString()
%
-Brock
DevelopMentor
http://staff.develop.com/ballen

0 comments:

Post a Comment