We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle null exception when exporting grid with foreign key columns?


When we export the grid with foreign key columns, the dataSource type of the foreign key columns is passed as generic object to the export function. As we don’t have support to export generic type list, a null exception is thrown like mentioned below.


System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
       at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordCell(Object row, Column column)
       at Syncfusion.EJ.Export.GridExcelExport.<>c__DisplayClasse.<ProcessRecordRow>b__d(Column column)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Syncfusion.EJ.Export.GridExcelExport.ProcessRecordRow(Object row)
       at Syncfusion.EJ.Export.GridExcelExport.RenderRecord()
       at Syncfusion.EJ.Export.GridExcelExport.ProcessGridContents()
       at Syncfusion.EJ.Export.GridExcelExport.IterateElements()
       at Syncfusion.EJ.Export.GridExcelExport.ExportHandler()
       at Syncfusion.EJ.Export.GridExcelExport.ExecuteResult(GridProperties GridModel, IEnumerable dataSource)
       at Syncfusion.EJ.Export.GridExcelExport.Export(GridProperties gridModel, IEnumerable dataSource, Boolean multipleExport)
       at Syncfusion.EJ.Export.ExcelExport.Export(GridProperties gridmaodel, IEnumerable datasource, String excelname, ExcelVersion excelversion, Boolean isHideColumnIncude, Boolean isTemplateColumnIclude, String theme)
       at EMIMReports._Default.dgReport_OnServerExcelExporting(Object sender, GridEventArgs e) in C:\Visual Studio Projects\2014\ESJS\EMIMReports\EMIMReports\Default.aspx.vb:line 99
       at Syncfusion.JavaScript.Web.Grid.PostBackEventHandler(String EventName, Dictionary`2 args)
       at Syncfusion.JavaScript.Web.CommonDataBoundControl.RaisePostBackEvent(String EventArgument)



Since we have deserialized the grid model obtained from the client side (where the column dataSource is a generic JSON object), it is deserialized to generic list


In order to overcome this issue, we need to dynamically set the dataSource for the foreign key columns before calling the Export method as explained in the below example.

Grid Rendering Code.


Code Behind


Article ID: Published Date: Last Revised Date: Platform: Control:
7132 10/31/2016 10/31/2016 ASP.NET MVC Grid
Did you find this information helpful?
Henryk Schneider Apr 27, 2018

This information should really be added to the main documentation around exporting -> https://help.syncfusion.com/aspnetmvc/grid/exporting

Fixed my problem.



Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon