I'm working on a C# Web Application project built in framework 3.5 where - for some odd reason I haven't figured out - the  
- (
But, when this value is binded - i.e: GvEmployee.DataBind();
- in the "RowDataBound
" event of the GridView called "GvEmployee
", the value is shown as:
4/03/2013 12:00:00 a. m.
- note the non-breaking space added.
and the System.FormatException
exception occurs:
System.FormatException: 'String was not recognized as a valid DateTime.'
This error is due the non-breaking space and the a.m.
additional string. If I remove those characters - while debugging at runtime - , the DateTime conversion can be done.
This the code where the error occurs:
protected void GvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
string id; // This is a reusable variable.
// Check rows only:
if (e.Row.RowIndex >= 0)
{
// Get the value stored in the given cell at the row:
id = e.Row.Cells[3].Text;
// Here, the value of "id" variable is: "4/03/2013 12:00:00 a. m.".
// But, the value returned by the database is: "04/03/2013 12:00:00 a.m.".
// Check if the "id" variable is not empty...
if (!id.Equals(" ") && !string.IsNullOrEmpty(id))
{
// Here fails, due to the value of "id" variable, that is: "4/03/2013 12:00:00 a. m."
// isn't recognized as a valid DateTime value.
e.Row.Cells[3].Text = Convert.ToDateTime(id, CultureInfo.CurrentCulture).ToShortDateString();
}
}
}
This is very strange since this project is already published and only happens on my notebook - I believe there is some missing configuration in the notebook I'm using for work on this project, but, I haven't found any clue about what that could be - I didn't know about non-breaking spaces until this problem happens to me and I found this