GenerateXlsxOutput throws exception Object reference not set to an instance of an object
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.UI.WebControls.ModelDataSourceView.FindMethod(String methodName) +165
System.Web.UI.WebControls.ModelDataSourceView.EvaluateSelectParameters() +75
System.Web.UI.WebControls.ModelDataSourceView.OnPageLoadComplete(Object sender, EventArgs e) +10
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnLoadComplete(EventArgs e) +9865142
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +795
1 comment
ADMIN
Attila Antal
Posted on:02 Nov 2021 13:47
Hello Valerio,
Thank you for reporting the problem.
During the investigation, we found that the problem only happens if Model Binding (SelectMethod, UpdateMethod, etc..) is used for the Controls in the FilterTemplate and the ExportSettings-ExportOnlyData property is set to "true".
Otherwise, it would work if binding programmatically or using Declarative DataSource controls such as SqlDataSource to bind data to the Controls.
Workaround
Currently, we can suggest turning the Filtering off for the Grid during the Export process. This could be a viable workaround to avoid the exception and still get the expected results.
protectedvoidRadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToExcelCommandName)
{
// Turn off the Filtering
RadGrid1.AllowFilteringByColumn = false;
// Apply the changes
RadGrid1.Rebind();
// Get the Export Outputvar GenXlsxOut = RadGrid1.MasterTableView.GenerateXlsxOutput();
// Change the Output as needed and proceed with the Export
}
}
If done in a Button's click.
protectedvoidRadButton1_Click(object sender, EventArgs e)
{
// Turn off the Filtering
RadGrid1.AllowFilteringByColumn = false;
// Apply the changes
RadGrid1.Rebind();
// Get the Export Outputvar GenXlsxOut = RadGrid1.MasterTableView.GenerateXlsxOutput();
// Change the Output as needed and proceed with the Export/*
* NOTE: If the Output is only needed to be saved for future use and not exporting it at all
* be sure to turn the filtering back on
*///RadGrid1.AllowFilteringByColumn = true; // Turn Filtering back on//RadGrid1.Rebind(); // Apply changes
}