One bug I’ve come across a few times and again just recently is when using an ObjectDataSource with a GridView to update dates. When doing the update the ObjectDataSource always uses the en-US culture and not the culture defined for the application.
The bug has been acknowledged by Microsoft but never fixed.
If you are in the US then you’ll have no problems, but if you are using a culture that uses the dd/MM/yyyy date format such as the UK or Australia you data will display in the correct format on your page, but you will get the following error when you try to save:
Cannot convert value of parameter ‘value’ from ‘System.String’ to ‘System.DateTime’
If your date is valid for the US format then you won’t get the error, but you day and month will be swapped over which is probably even more annoying.
This can be fixed by hooking into the RowUpdating event of the GridView. The RowUpdating event is fired before the update takes place and it is simple to find any date values and change the format of them:
using System.Collections;
using System.Globalization;
protected void gvStudents_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
foreach (DictionaryEntry de in e.NewValues)
{
DateTime currentDate = DateTime.MinValue;
if (de.Value != null && DateTime.TryParse(de.Value.ToString(), out currentDate))
{
e.NewValues[de.Key] = currentDate.ToString(new CultureInfo("en-US"));
}
}
}



Exactly what I was looking for. Tnx!
Hi,
I had exactly same issue, but found out it was not a framework bug.
The error occurred only when I was using the built-in web server.
Try switching your project to IIS instead and see if it helps.
There is no need for any workarounds…
Regards,
Robert
Hi Robert
Thanks for the insight.
When I first came across the issue it definately was a framework bug that was verified by Microsoft here.
What if you put this?
- EnableScriptGlobalization=”true”
I think it works
ASP.NET 3.5-> What’s new:
Support for script globalization and localization by using client script. Globalization enables you to display dates and numbers based on a culture value (locale). Localization enables you to specify localized content (text, images, and so on) in client components for UI elements or exception messages.
Source:
http://msdn.microsoft.com/en-us/library/s57a598e.aspx
So, I think it works
EnableScriptGlobalization=”true”
Luis
EnableScriptGlobalization is something completely different to the subject of this post.
EnableScriptGloablization and EnableScriptLocalization are used when displaying information with JavaScript.
The problem outlined in my post is a bug with the ObjectDataSource when performing an update, not when displaying data. The ObjectDataSource uses ConvertFromInvariantString which is what causes the issue and therefore the workaround is required.
Robert
I tried using IIS as you suggested but this still doesn’t solve the issue as the ObjectDataSource is still using ConvertFromInvariantString.
Muchas gracias!!!