Remove Header Columns when export to excel and CSV

8 posts, 0 answers
  1. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 12 Aug 2011 Link to this post

    Hi,

    we have a radgrid and we are binding the radgrid with datatable the grid height and width is "0px" while we export to excel or csv we want to remove its header column name is there any possiblities to remove this? Below is my code :

    //HTML code
    <telerik:RadGrid ID="rgExport" runat="server" Height="0" Width="0"
                        onitemdatabound="rgExporthierarchical_ItemDataBound"
                        onexcelmlexportrowcreated="rgExporthierarchical_ExcelMLExportRowCreated">
                    </telerik:RadGrid>

    //.CS file Code
    rgExport.DataSource=dt;
    rgExport.DataBind();

    please reply soon we will very thankful to you.

    thanks & regards
    BHARAT VEER
  2. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 15 Aug 2011 Link to this post

    Hello Bharat,

    You can remove the header row by setting ShowHeader to false. Simple demo is shown below:
    <asp:Button ID="Button1" runat="server" Text="Export" />
    <telerik:RadGrid ID="RG1" runat="server" />


    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
     
        RG1.NeedDataSource += (s, a) =>
            {
                DataTable table = new DataTable();
     
                table.Columns.Add("Column1");
                table.Columns.Add("Column2");
                for (int i = 0; i < 10; i++)
                    table.Rows.Add(i, i);
                RG1.DataSource = table;
            };
     
        Button1.Click += (s, a) =>
        {
            RG1.ShowHeader = false;
            RG1.Rebind();
            RG1.MasterTableView.ExportToCSV();
        };
    }



    Best regards,
    Daniel
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. bharat veer
    bharat veer avatar
    41 posts
    Member since:
    Dec 2009

    Posted 17 Aug 2011 Link to this post

    Thanks Daniel !!!!! but it is only working for CSV. It is not working for Excel. Can you please provide me solution for excel as well as. Please reply soon.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Aug 2011 Link to this post

    Hello Bharat,

    You can try the following code snippet to achieve your scenario.

    C#:
    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
          if (e.CommandName == RadGrid.ExportToExcelCommandName)
          {
              GridHeaderItem HeaderItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
              HeaderItem.Visible=false;
          }
    }

    Thanks,
    Princy.
  6. Rasheed
    Rasheed avatar
    3 posts
    Member since:
    Sep 2014

    Posted 06 Nov 2014 Link to this post

    I want to remove the header of Detail Table.
    How can it possible.
    And moreover Itemcommand event is not firing when clicking on Export to Excel button.
  7. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 11 Nov 2014 Link to this post

    Hello Rasheed,

    I've created a sample RadGrid web site to demonstrate how you can achieve the requested functionality. Please run the attached application and let me know if it helps you.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  8. Jorge
    Jorge avatar
    2 posts
    Member since:
    Oct 2014

    Posted 25 Jul 2015 in reply to Eyup Link to this post

    Hi

    Not work for me!

    Please see the picture. I need remove the header row for each DetailTables.

    I hope your help!

  9. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 30 Jul 2015 Link to this post

    Hi Jorge,

    Could you share your exporting settings and configuration so I can prepare a web site sample resembling your scenario?

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017