Problem
When the columns bound to the Grid are not defined in the Grid dataSource, and are passed to the exporting method in Code behind, a null exception is thrown as follows.
<Exception>
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Syncfusion.EJ.Export
StackTrace:
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)
InnerException:
</Exception>
Reason
The dataSource passed to the exporting method is compared with the Grid dataSource. Thus, when a column is not defined in the Grid dataSource, it is obtained as null value and hence throws a null exception.
Solution
You need to ensure that the columns bound to the Grid are defined in the Grid dataSource before exporting the Grid.
I ran into this problem and my columns were the same as the grid but did not solve the problem, what solved it was remove the filter. I was filtering the grid before export but the items in the controller have no filtering. ej Grid = 2 rows, datasource before the export is called have 4 rows, making the error appear. Once both have synchronized data, it started working.
Hi Theresa,
To find out the root cause we need the following details,
1. Code example of a Grid and Controller.
2. Have you used foreignKey column in Grid?
3. Essential Studio Version details.
4. Share the business object model.
5. If possible send me the issue reproduceable sample.
Regards,
Prasanna Kumar N.S.V
Recently a had the same problema, and my DataSource was complete, so for a log time I couldn't figure it out, it end up been a problem with the GridProperties.SummaryRows that for some reason had some information in it and, when resetted to new List, worked just fine.