I am returning bound data to a RadGridView via a DataTable. In the process I need to modify one of the columns which is contains a timestamp value (seconds from midnight) to display time. The code below shows where I intercept the column in the CellFormatting event and convert the timestamp value to a DateSerial, which I then set the CellElement.Text to.
Based on this function the grid displays the timestamp exactly as I want - ie: 44233 is displayed correctly as 12:17:13 PM in the grid. However, when export the grid to Excel, the timestamp value (44233) is exported and not the new CellElement.Text.
Am I doing something wrong or can I modify the column via the exporter before it gets into Excel? Thanks
Based on this function the grid displays the timestamp exactly as I want - ie: 44233 is displayed correctly as 12:17:13 PM in the grid. However, when export the grid to Excel, the timestamp value (44233) is exported and not the new CellElement.Text.
Am I doing something wrong or can I modify the column via the exporter before it gets into Excel? Thanks
Private
Sub
grdAccessLogs_CellFormatting(sender
As
Object
, e
As
CellFormattingEventArgs)
Handles
grdAuditLogs.CellFormatting
Dim
sCol
As
String
= e.CellElement.ColumnInfo.Name.ToUpper
'format timestamp column
If
sCol.IndexOf(
"TYPE=TS"
) > 0
Then
Dim
sTs
As
String
= e.CellElement.Text
If
e.CellElement.Text.IndexOf(
":"
) = -1
Then
e.CellElement.Text = fConvertSysTime(sTs).ToString
End
If
End
Sub
Function
fConvertSysTime(lTime
As
Integer
)
As
String
Dim
lHours
As
Integer
Dim
lMinutes
As
Integer
Dim
lSeconds
As
Integer
Try
'truncate decimals - only want full hours
lHours = Int(lTime / 3600)
lMinutes = Int((lTime - lHours * 3600) / 60)
lSeconds = Int(lTime - lHours * 3600 - lMinutes * 60)
'build time string
Return
TimeSerial(lHours, lMinutes, lSeconds)
Catch
e
As
Exception
Return
""
End
Try
End
Function