I have a RadGrid that works just fine except for one small issue when exporting to excel. I have a template column that uses OnItemCreated to custom format that column. Debugging through the code it seems that during the OnItemCreated event the e.Item.DataItem is null during export but during normal usage of the grid this value is there. Perhaps I am doing this completely backward but I think I'm on the right track but may just be missing some small property change or something. The template column on export has no data while the grid in the browser does. See attached screenshots. Here's my code:
Thanks for any help!
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid_CompletedTrainingReport"
OnNeedDataSource
=
"RadGrid_CompletedTrainingReport_NeedDataSource"
OnDetailTableDataBind
=
"RadGrid_CompletedTrainingReport_OnDetailTableDataBind"
OnItemCreated
=
"RadGrid_CompletedTrainingReport_OnItemCreated"
ExportSettings-ExportOnlyData
=
"true"
ExportSettings-Excel-Format
=
"Html"
AllowSorting
=
"true"
EnableHeaderContextMenu
=
"true"
OnCustomAggregate
=
"RadGrid_CompletedTrainingReport_OnCustomAggregate"
>
<
MasterTableView
DataKeyNames
=
"TrainingTrackingID"
Name
=
"TrainingTrackings"
AutoGenerateColumns
=
"false"
CommandItemDisplay
=
"TopAndBottom"
CommandItemSettings-ShowExportToExcelButton
=
"true"
CommandItemSettings-ShowAddNewRecordButton
=
"false"
ExpandCollapseColumn-Visible
=
"true"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"StudentFullname"
HeaderText
=
"Student Name"
SortExpression
=
"StudentLastname"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"TrainingName"
HeaderText
=
"Training Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ILACode"
HeaderText
=
"ILA Code"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CompletedDate"
HeaderText
=
"Completion Date"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Certificate Number"
>
<
ItemTemplate
>
<
asp:ImageButton
ID
=
"ImageButton_PrintCertificate"
ImageUrl
=
"~/images/Certificate.png"
runat
=
"server"
AlternateText
=
"Print Certificate"
/>
<
asp:Label
Text='<%# Eval("CertificationNumber") %>'
runat="server"
ID="Label_CertificateNumber"/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"CEHour"
HeaderText
=
"CE Hour"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"SimHour"
HeaderText
=
"Sim Hour"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"StandHour"
HeaderText
=
"Stand Hour"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"EOHour"
HeaderText
=
"EO Hour"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"PJMHour"
HeaderText
=
"PJM Hour"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ProfHour"
HeaderText
=
"Prof Hour"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"SOCCEDUploadMessage"
HeaderText
=
"SOCCED Message"
HeaderStyle-Width
=
"10%"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
DetailTables
>
<
telerik:GridTableView
DataKeyNames
=
"ID"
Name
=
"LessonTrackings"
AutoGenerateColumns
=
"false"
ShowFooter
=
"true"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Name"
HeaderText
=
"Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Type"
HeaderText
=
"Type"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Status"
HeaderText
=
"Status"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Score"
>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"HyperLink_Score"
CssClass
=
"HyperLink_Score_Class"
runat
=
"server"
Text='<%# Eval("Score") %>'/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"SecondsOn"
HeaderText
=
"Time Spent On (hh:mm:ss)"
Aggregate
=
"Custom"
FooterText
=
"Total Time: "
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"Label_SecondsOn"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
telerik:GridTableView
>
</
DetailTables
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected
void
RadGrid_CompletedTrainingReport_OnItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
GridDataItem gdi = (GridDataItem)e.Item;
if
(gdi.OwnerTableView.Name ==
"Registrations"
)
{
if
(gdi.DataItem
is
spTrainingStatusReport_Result)
{
var spTrainingStatusReport_Result = (spTrainingStatusReport_Result)gdi.DataItem;
var Label_SecondsOn = (Label)gdi.FindControl(
"Label_SecondsOn"
);
var SecondsOnTimespan =
new
TimeSpan(0, 0, spTrainingStatusReport_Result.SecondsOnTraining);
Label_SecondsOn.Text = SecondsOnTimespan.ToString(
"c"
);
}
}
}
}
Thanks for any help!