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

Programmatic Creation of RadGrid with Export to excel/pdf

2 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vijayaraj
Top achievements
Rank 1
Vijayaraj asked on 23 May 2011, 01:41 PM
Hi,

I am trying to create a Radgrid from the codebehind at runtime. The grid works fine with paging, but the problem is i need to have the export functionality I tried the following code along with the grid creation even then the grid header is not displayed.

               RadGrid1.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true;
               RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = true;
               RadGrid1.MasterTableView.CommandItemSettings.ShowRefreshButton = true;
               RadGrid1.ExportSettings.HideStructureColumns = true;
               RadGrid1.ExportSettings.ExportOnlyData = true;
               RadGrid1.ExportSettings.IgnorePaging = true;
               RadGrid1.ExportSettings.OpenInNewWindow = true;

Am i missing something? 

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Vijayaraj
Top achievements
Rank 1
answered on 23 May 2011, 11:43 PM
I did a work around using the commanditemtemplate,

RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
 RadGrid1.MasterTableView.CommandItemTemplate = new MyCommandItemTemplate();


class MyCommandItemTemplate : ITemplate
  {
        protected LinkButton refreshButton;
        protected LinkButton exportButton;
        public MyCommandItemTemplate()
       {
       }
        public void InstantiateIn(System.Web.UI.Control container)
       {
           refreshButton = new LinkButton();
           refreshButton.ID = "refreshButton";
           refreshButton.Text = "Refresh grid";
           refreshButton.CommandName = "Rebind";
            exportButton = new LinkButton();
           exportButton.ID = "exportButton";
           exportButton.Text = "Export grid excel";
           exportButton.CommandName = "exporttoexcel";
           container.Controls.Add(exportButton);
            container.Controls.Add(refreshButton);
       }
   }

Regards,
Vijay
0
Daniel
Telerik team
answered on 26 May 2011, 02:50 PM
Hello Vijayaraj,

The code in the first sample will work properly if you enable the CommandItem row .
RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
RadGrid1.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true;

You don't have to use templates except if you need to customize the command item row.

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.

Tags
Grid
Asked by
Vijayaraj
Top achievements
Rank 1
Answers by
Vijayaraj
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or