Hi, I'm difficulty with exported date formats in my mulicultural application.
The issue is that users within my application are allowed to change their language (thus, their culture setting within our application) but the radgrid's exports seem to "stick" to whatever their previous culture's date format is. This "sticking" behavior is regardless of which culture is started with and then changed to.
To support multiple dates, I'm applying a DataFormatString of "{0:d}" to the GridDateTimeColumn so I can allow .NET to auto-format it with the builtin Globalization features. So my column is defined like this:
<telerik:GridDateTimeColumn ItemStyle-Wrap="false" HeaderText="<%$ Resources: OurstringsResource, HeaderTextInvoiceDate %>" DataField="invDate" HeaderStyle-Width="8em" DataFormatString="{0:d}" />
When applying this format, the on-screen date is shown correctly, however it is not when exporting in the same format as shown on the screen. Again, this is after they've changed their language/culture. All other aspects of our application regarding the culture change work correctly (e.g. I am debugging the code and can see the correct culture is set) so I'm confident it is not a problem with our application.
I've found a number of posts on the Telerik site describing similar behavior, but in my case I'm using the Xlsx format, such as this:
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
RadGrid1.ExportSettings.FileName = "MyExportedFile";
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.Excel.Format = GridExcelExportFormat.Xlsx;
RadGrid1.MasterTableView.ExportToExcel();
}
Since we are using the format of Xlsx I don't see many events that I can change the format, per the many suggestions found in the other threads. I did see that OnItemCreated looked promising and I tried doing something like this:
if (e.Item is GridDataItem && exporting)
{
var item = (GridDataItem)e.Item;
//also tried manually setting the specific short date as defined by the current culture
item["invDate"].Text = Convert.ToDateTime(item["invDate"].Text).ToString("d");
}
... but this didn't work.
I've tried many other things such as changing my column type, setting the appropriate culture in either/both the Page.Culture and RadGrid.Culture, binding the DataFormatString string to a fixed string appropriate for the culture, etc etc etc.
I'm really at a loss here and could use some help.
Thanks in advance!
BTW, I'm using the Q1 2016 version of UI for ASP.NET AJAX, and .NET 4.5.