[Bug] RadGrid - Hierarchy Export To Excel (Format ExcelML)

4 posts, 0 answers
  1. SomeName
    SomeName avatar
    19 posts
    Member since:
    Jul 2011

    Posted 15 Jul 2011 Link to this post

    Hi.

    I have stumbled over a bug (Atleast i think its one).
    I want to expert my nested table view into excel. (excel-format: ExcelML)
    Word, CSV and Excel with format Html works fine.

    But ExcelML crashes with a null exception.

    ASPX.Page:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestGrid.aspx.cs" Inherits="TestGrid" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"
            EnableLinqExpressions="false">
            <ExportSettings HideStructureColumns="true" ExportOnlyData="true" IgnorePaging="true"
                Excel-Format="ExcelML" />
            <PagerStyle Mode="NumericPages" AlwaysVisible="true" />
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView ShowHeader="true" AutoGenerateColumns="False" AllowPaging="true"
                DataKeyNames="ID, PARENT_ID" CommandItemDisplay="Top" AllowMultiColumnSorting="True"
                EditMode="InPlace" HierarchyLoadMode="Client" FilterExpression="PARENT_ID = 0 or PARENT_ID IS NULL">
                <CommandItemTemplate>
                    <asp:Button  ID="ExportToExcelButton" runat="server"
                        CommandName="ExportToExcel" Text="Export to Excel" />
                    <asp:Button  ID="ExportToWordButton" runat="server"
                        CommandName="ExportToWord" Text="Export to Word" />
                    <asp:Button  ID="ExportToCsvButton" runat="server"
                        CommandName="ExportToCsv" Text="Export to Csv" />
                </CommandItemTemplate>
                <SelfHierarchySettings ParentKeyName="PARENT_ID" KeyName="ID" MaximumDepth="0" />
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" />
                    <telerik:GridBoundColumn DataField="PARENT_ID" />
                    <telerik:GridBoundColumn DataField="NAME" />
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        </form>
    </body>
    </html>

    ASPX.CS Code Page:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using Telerik.Web.UI;
     
        public partial class TestGrid : System.Web.UI.Page
        {
     
            protected void Page_Load(object sender, EventArgs e)
            {
     
            }
     
            private DataTable GetDataTable()
            {
                DataTable returnValue = new DataTable();
     
                returnValue.Columns.Add("ID");
                returnValue.Columns.Add("PARENT_ID");
                returnValue.Columns.Add("NAME");
     
                DataRow row = returnValue.NewRow();
                row["ID"] = 1;
                row["PARENT_ID"] = 0;
                row["NAME"] = "Parent A";
                returnValue.Rows.Add(row);
     
                row = returnValue.NewRow();
                row["ID"] = 2;
                row["PARENT_ID"] = 1;
                row["NAME"] = "Child A";
                returnValue.Rows.Add(row);
     
                row = returnValue.NewRow();
                row["ID"] = 3;
                row["PARENT_ID"] = 1;
                row["NAME"] = "Child B";
                returnValue.Rows.Add(row);
     
                row = returnValue.NewRow();
                row["ID"] = 4;
                row["PARENT_ID"] = 1;
                row["NAME"] = "Child C";
                returnValue.Rows.Add(row);
     
                row = returnValue.NewRow();
                row["ID"] = 5;
                row["PARENT_ID"] = 0;
                row["NAME"] = "Parent B";
                returnValue.Rows.Add(row);
     
                return returnValue;
            }
     
            protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                RadGrid1.DataSource = GetDataTable();
            }
        }

  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 21 Jul 2011 Link to this post

    Hello,

    I'm afraid RadGrid does not support exporting with self-referencing hierarchy.
    Please excuse us for any inconvenience caused.

    Best regards,
    Daniel
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. SomeName
    SomeName avatar
    19 posts
    Member since:
    Jul 2011

    Posted 22 Jul 2011 Link to this post

    This cant be true, as I mentioned it works fine with every export function except for Excel in the format ExcelML.
    So why should everything be supported except for ExcelML? (Exporting Excel with HTML works fine aswell)
  5. Asutosh
    Asutosh avatar
    130 posts
    Member since:
    Sep 2013

    Posted 17 Jun 2014 in reply to Daniel Link to this post

    hi

    i am exporting heirarchy radgrid in excel

    how to export radgrid in excel without OnNeedDataSource

    i am binding datasource to radgrid on button click event 

    if i am not use OnNeedDataSource,it give me object reference is null

    my code for binding grid is 

     grd_firstchart_aco.DataSource = table;

     grd_firstchart_aco.DataBind();
    and code for export to excel is below
      grd_forth_aco.ExportSettings.ExportOnlyData = true;
            grd_forth_aco.ExportSettings.IgnorePaging = true;
            grd_forth_aco.ExportSettings.OpenInNewWindow = true;
            grd_forth_aco.ExportSettings.FileName = "fileName";
            grd_forth_aco.ExportSettings.Excel.Format = GridExcelExportFormat.ExcelML;
            grd_forth_aco.ExportSettings.HideStructureColumns = true;

            grd_forth_aco.MasterTableView.HierarchyDefaultExpanded = true;
            grd_forth_aco.MasterTableView.DetailTables[0].HierarchyDefaultExpanded = true;

            grd_forth_aco.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client;
            grd_forth_aco.MasterTableView.DetailTables[0].HierarchyLoadMode = GridChildLoadMode.Client;

            grd_forth_aco.MasterTableView.ExportToExcel();


    thanks

Back to Top