Good afternoon,
I was wondering if anyone could help me with a GridView export issue I am having.
I am populating a GridView from an SQL query. This table has two DateTime columns that I am formatting after the DataBindingComplete to show the milliseconds portion of the DateTime field like so:
private
void
dgvTransTable_DataBindingComplete(
object
sender, GridViewBindingCompleteEventArgs e)
{
for
(
int
j = 0; j <
this
.dgvTransTable.Columns.Count; j++)
{
if
(
this
.dgvTransTable.Columns[j].GetType() ==
typeof
(Telerik.WinControls.UI.GridViewDateTimeColumn))
{
((GridViewDateTimeColumn)
this
.dgvTransTable.Columns[j]).FormatString =
"{0:MM/dd/yyyy hh:mm:ss.fff}"
;
}
}
}
Works great. Column displays just like I want. Now the problem is with the Excel Export. Normally with the format cell options, you can use .000 for milliseconds. I just can't seem to get it correct with the GridViewSpreadExport. This is what I am trying, note I've also tried using the .fff but it both cases, all that is written to the Excel cell is the short date/time string, and the formatting looks like I want, except either just the literal .fff or .000 show up in the visual cell.
I'd even be happy if someone knows how to make this field export as a straight text field as long as the string is formatted like the gridview cell.
foreach
( GridViewDataColumn col
in
dgvTransTable.Columns )
{
switch
( col.DataType.Name )
{
case
nameof(DateTime):
col.ExcelExportType = Telerik.WinControls.UI.Export.DisplayFormatType.Custom;
col.ExcelExportFormatString =
"MM/dd/yyyy hh:mm:ss.000"
;
break
;
}
}