This is a migrated thread and some comments may be shown as answers.

NullReference Export Exception

2 Answers 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pooya
Top achievements
Rank 1
Pooya asked on 12 Jul 2011, 10:33 AM
I have a RadGrid which is created programmatically. When I click the Export to Excel or Word button, it raises this issue and I can't debug what's causing it as it's inside the Telerik assembly:

What does AdjustStructureColumnCells() do? any clue what I can do?

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Web.UI.Grid.Export.TableViewExporter.AdjustStructureColumnCells(GridTableView tableView) +874
   Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExportInternal(GridTableView tableView, Boolean ignorePaging, Boolean dataOnly) +267
   Telerik.Web.UI.Grid.Export.TableViewExporter.page_PreRender(Object sender, EventArgs e) +23
   System.EventHandler.Invoke(Object sender, EventArgs e) +0
   System.Web.UI.Control.OnPreRender(EventArgs e) +8926370
   System.Web.UI.Control.PreRenderRecursiveInternal() +103
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Jul 2011, 11:43 AM
Hello Pooya,

I tried the same scenario and its working as expected in my end. Here is the sample code that I tried.

C#:
protected void Page_Load(object sender, EventArgs e)
{
      RadGrid RadGrid1 = new RadGrid();
       RadGrid1.ID = "RadGrid1";
       PlaceHolder1.Controls.Add(RadGrid1);
       if (!IsPostBack)
       {        
           RadGrid1.AllowPaging = true;
           RadGrid1.MasterTableView.AutoGenerateColumns = false;
           RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = true;
           RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
           RadGrid1.ExportSettings.ExportOnlyData = true;
           RadGrid1.NeedDataSource += new GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource);
           RadGrid1.PageSize = 15;
           GridBoundColumn boundColumn;
           boundColumn = new GridBoundColumn();
           RadGrid1.MasterTableView.Columns.Add(boundColumn);
           boundColumn.DataField = "EmployeeID";
           boundColumn.HeaderText = "EmployeeID";
        }
 void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       RadGrid radgrid= sender as RadGrid;
      
radgrid.DataSource = BindGrid();
   }
   protected DataTable BindGrid()
   {
       SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString);
       SqlCommand cmd = new SqlCommand("select * from Employee", con);
       SqlDataAdapter ad = new SqlDataAdapter(cmd);
       DataTable ds = new DataTable();
       ad.Fill(ds);
       return ds;
   }
}

Thanks,
Princy.
0
Pooya
Top achievements
Rank 1
answered on 13 Jul 2011, 10:26 AM
I found the problem:

I had set the HierarchyDefaultExpanded property to true where there was no detailTable for a GridTableView.

I believe the Telerik assembly should be improved to either ignore this property when there is no detail table or catch and throw a proper exception message to help fixing it.


Tags
Grid
Asked by
Pooya
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Pooya
Top achievements
Rank 1
Share this question
or