Column Headers not being exported to Excel when More then 10 Rows are exported

2 posts, 0 answers
  1. Tim
    Tim avatar
    60 posts
    Member since:
    May 2011

    Posted 21 Feb 2012 Link to this post

    2 problems here;
    1. Header row (column titles) are not exported to Excel when I have more than 10 items in a export. I thought it might be related to the page size so I changed my page size to encompass 12 rows and still no header row.
    2. I am unable to get the entire dataset to export to excel. I can only get the 1st page. See code snipit

    ActiveBatchesRadGrid_ItemCommand calls the method ConfigureExport in the base class so all exports function the same

    private void ActiveBatchesRadGrid_ItemCommand(object source, GridCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case RadGrid.InitInsertCommandName:
                _gridTableView = e.Item.OwnerTableView;
                break;
            case RadGrid.ExportToExcelCommandName:
                ExpandAllDetailTableRecords(source, ExpandedStates, false);
                ConfigureExport(source, e);
                break;
        }
     
     }



    protected static void ConfigureExport(object source, GridCommandEventArgs e)
    {
        e.Item.OwnerTableView.ExpandCollapseColumn.Visible = false;
        e.Item.OwnerTableView.GetColumn("PolicyEditRecord").Visible = false;
        e.Item.OwnerTableView.GetColumn("DeleteTransaction").Visible = false;
        e.Item.OwnerTableView.GetColumn("ManualAdjustmentBatchID").Visible = false;
        e.Item.OwnerTableView.GetColumn("ManualAdjustmentID").Visible = false;
        ((RadGrid)source).ExportSettings.ExportOnlyData = true;
        //((RadGrid)source).PageSize = ((RadGrid)source).MasterTableView.VirtualItemCount;
        ((RadGrid)source).ExportSettings.IgnorePaging = true;
        ((RadGrid)source).ExportSettings.OpenInNewWindow = false;
        ((RadGrid)source).MasterTableView.HierarchyDefaultExpanded = false;
        ((RadGrid)source).MasterTableView.ExportToExcel();
     
    }

    VirtualItemCount is commented out because it throws an "System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values." error. I have not tried it yet but I think it may be due to the export being conducted on the DetailGrid and not the MasterGrid. Any comments on that would be appreciated too.


    EDIT:
    After further investigation the lack of the export of the header row does not appear to be a row count issue. It appears that only the first DetailGrid of the first row of the MasterDetailGrid exports the column headers. I have tried this on all of my implementations and the behavior is consistent across them
  2. Tim
    Tim avatar
    60 posts
    Member since:
    May 2011

    Posted 22 Feb 2012 Link to this post

    Ok, I think I solved issue number 1.
    I am using a modified RadGrid State Management as described in this article my ExpandAllDetailTableRecords is in the base class so all grids can call the same process.

    I was passing false to expanded instead of using the (bool)expandedStates[key] to set my Item expanded state. so the for {} statement was always closing the header row. The intent for this process was to make sure that all DetailGrids that are children of the rows of this DetailGrid are closed prior to export.

    Uncorrected Code:
    protected static void ExpandAllDetailTableRecords(object source, Hashtable expandedStates, bool expanded)
    {
        string[] indexes = new string[expandedStates.Keys.Count];
        expandedStates.Keys.CopyTo(indexes, 0);
        ArrayList arr = new ArrayList(indexes);
        arr.Sort();
         
        foreach (string key in from string key in arr let value = (bool)expandedStates[key] where value select key)
        {
            ((RadGrid)source).Items[key].Expanded = expanded;
        }
    }

    Corrected Code:
    protected static void CloseAllDetailTableRecords(object source, Hashtable expandedStates)
    {
        string[] indexes = new string[expandedStates.Keys.Count];
        expandedStates.Keys.CopyTo(indexes, 0);
        ArrayList arr = new ArrayList(indexes);
        arr.Sort();
     
        foreach (string key in arr.Cast<string>().Where(key => key.Contains(":")))
        {
            ((RadGrid)source).Items[key].Expanded = false;
        }
    }




  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top