radgrid excel export missing column headers

3 posts, 0 answers
  1. Donna
    Donna avatar
    8 posts
    Member since:
    Jun 2016

    Posted 26 Jul 2017 Link to this post

    I am troubleshooting a program that someone else wrote and there is a grid that is missing a few column headers upon export to excel.  The column headers and data showed up on screen but not on excel export.  The first few columns would have headers and the rest of the columns displayed data but no headers.  In the method that gets called by OnItemCommand, I have tried changing the header text by doing this:

    gridMasterTableView.GetColumn(I).HeaderText = I;

    but it doesn't seem to change anything on the excel.

    In the method that is called by OnItemDataBound I tried to put a breakpoint on this line:

    GridHeaderItem header = (GridHeaderItem)e.Item;

    In the GridHeaderItem I noticed it only has a few of the columns.

    I just want to fill the missing column headers.  Is there a good place where I can access the datatable that gets exported to excel and put in the headers?  In other words, if I only want to control what column name to put on excel export without touching the original source data, what would be a good place to do it and how to go about doing that?


  2. Donna
    Donna avatar
    8 posts
    Member since:
    Jun 2016

    Posted 26 Jul 2017 Link to this post

    upon further investigation, I noticed that on the aspx page mastertableview is missing the columns that require headings.  The ones that have headings on the excel file, their columns are specified on the aspx page. 

    Those columns missing headers were added in the code behind during grid binding:


    for (int i = 2011; i <= currentyear; i++)





    GridNumericColumn boundColumn = new GridNumericColumn();

    boundColumn.DataField = ""+i;

    boundColumn.HeaderText = ""+i;

    boundColumn.UniqueName = ""+i;




    boundColumn.Aggregate = GridAggregateFunction.Sum;

    boundColumn.FooterText = " ";

    boundColumn.HeaderStyle.Width = new Unit(65);

    boundColumn.HeaderText = ""+i;

    boundColumn.DataField = "" + i;

    boundColumn.ReadOnly = true;

    boundColumn.UniqueName = "" + i;

    boundColumn.DataType = typeof(System.Double);

    //boundColumn.ColumnType =

    boundColumn.NumericType = NumericType.Currency;

    boundColumn.FooterAggregateFormatString = "{0:C}";










    Would adding columns from code behind wipe out the column headers?

    Would rebinding the grid at later point wipe out the headers?


    I am just throwing ideas around as I'm at a lost on how to make the column headers show up on the excel export file.



  3. Eyup
    Eyup avatar
    4085 posts

    Posted 31 Jul 2017 Link to this post

    Hi Donna,

    Please note that mixing declarative columns defined in the aspx page with programmatically added ones is not supported. If you need to create the grid programmatically, please create the entire grid on the code-behind during the Page_Init event handler. In the aspx page you can put a asp:PlaceHolder element. You can check the following section for instructions:

    Also, make sure you are not using DataBind() method to bind the grid. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:

    Declarative DataSource (DataSourceID property)
    Programmatic Data Binding (NeedDataSource event, + DetailTableDataBind for hierarchy). You should set the DataSource property ONLY within these event handlers.

    I hope this will prove helpful.

    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top