Programmatic Creation of RadGrid with Export to excel/pdf

3 posts, 0 answers
  1. Vijayaraj
    Vijayaraj avatar
    25 posts
    Member since:
    Mar 2011

    Posted 23 May 2011 Link to this post

    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. Vijayaraj
    Vijayaraj avatar
    25 posts
    Member since:
    Mar 2011

    Posted 23 May 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Daniel
    Admin
    Daniel avatar
    4943 posts

    Posted 26 May 2011 Link to this post

    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.

Back to Top