Connecting Tech Pros Worldwide Help | Site Map

String was not recognized as a valid DateTime

Patrick Olurotimi Ige
Guest
 
Posts: n/a
#1: Nov 19 '05
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 ***
Patrick Olurotimi Ige
Guest
 
Posts: n/a
#2: Nov 19 '05

re: String was not recognized as a valid DateTime


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 ***
Neverlyn
Guest
 
Posts: n/a
#3: Nov 19 '05

re: String was not recognized as a valid DateTime


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:
[color=blue]
> 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 ***
>[/color]
Brock Allen
Guest
 
Posts: n/a
#4: Nov 19 '05

re: String was not recognized as a valid DateTime


> <asp:Label runat="server" width="40%" text='[color=blue]
> <%#
> DateTime.Parse(DataBinder.Eval(Container,"DataItem .dt").ToString()).To
> Sh
> ortDateString()%>' id="Label6">[/color]

Why don't you just do this instead:

<%# ((DateTime)DataBinder.Eval(Container.DataItem, "dt")).ToShortDateString()
%>

-Brock
DevelopMentor
http://staff.develop.com/ballen




Closed Thread