Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > RadControls in DotNetNuke > Telerik RadGrid ExportToPDF() or ExportToExcel() not working

Not answered Telerik RadGrid ExportToPDF() or ExportToExcel() not working

Feed from this thread
  • Manish Mishra avatar

    Posted on Jan 12, 2012 (permalink)

    I have a simple class inheriting RadGrid. Am adding a button to the RadGrid and a Click Event handler of that button. Everything's working fine i.e. Button gets added to the required position. It fires the handler as well, but nothing happens. radGrid.MasterTableView.ExportToExcel()is not doing anything. Infact upon click and when page posts back, now the button is gone. What's Happening?? I tried to add the button control to the Page.Form control collection, but still nothing happens.


    [ToolboxData("<{0}:RadGridDp runat=server></{0}:RadGridDp>")]
    public class RadGridDP : RadGrid
    {
     
        public RadGridDP()
        {
     
        }
        protected override void OnLoad(EventArgs e)
        {
     
            base.OnLoad(e);
            Button btnExport = new Button();
            btnExport.ID = "Export";
            btnExport.Text = "Export";
            btnExport.Click += new EventHandler(btnExport_Click);
            btnExport.CommandArgument = this.ID;
            this.MasterTableView.Controls.Add(btnExport);
     
        }
     
        void btnExport_Click(object sender, EventArgs e)
        {
     
            Button btnExport = (Button)sender;
            string RadGridId = btnExport.CommandArgument.ToString();
            RadGridDP radGrid = (RadGridDP)this.Parent.Parent.FindControl(RadGridId);
     
            radGrid.ExportSettings.IgnorePaging = true;
            radGrid.ExportSettings.OpenInNewWindow = true;
            radGrid.ExportSettings.ExportOnlyData = true;
     
            radGrid.MasterTableView.ExportToExcel();
        }
     
    }


    When i do same thing in a UserControl and use that UC on any page, it works fine. Please look into my problem.


    Reply

  • Posted on Jan 12, 2012 (permalink)

    Hi Manish,
    Have you stepped through the code to make sure you have the right control on this line?

    RadGridDP radGrid = (RadGridDP)this.Parent.Parent.FindControl(RadGridId); 

    Thank you,
    James Campbell

    If this helps answer your question please mark as answered, thank you.

    Reply

  • Manish Mishra avatar

    Posted on Jan 13, 2012 (permalink)

    hello James...thanks for your response...
    yeah..i have right control on that line.
    See what's happening is..upon click after  executing btnExport_Click handler, control goes to the NeedDataSource handler defined on the Page(the radGrid is kept upon) and rebinds the grid. May be due to that Export is not happening.

    So I guess my solution is to call this btnExport_Click after NeedDataSource handler gets executed..how can i do that?? 
    Interestingly, am getting correct grid in the btnExport_Click with item count and virtual item count > 0. So that means, Grid is already bound to data, so why NeedDataSource handler fires up again??? 

    Please tell me what's happening?

    Reply

  • Posted on Jan 14, 2012 (permalink)

    I will attempt to implement this and see if I can recreate. What version of DNN are you running?


    -Jim

    Reply

  • Manish Mishra avatar

    Posted on Jan 16, 2012 (permalink)

    hello James..I got my objective done, but not the way I have posted here as  question. All i needed was a button on the radGrid to do the Export, and  that also without going to each of the individual RadGrids (on various pages). So when I added a button along with its handler, upon Click, various events would fire in this order:

    -Page OnLoad
    -RadGridDP OnLoad
    -Button_Click
    -RadGridDP OnNeedDataSource

    So entire RadGrid would rebind and Export won't happen.
    But all i had to do is this:
    public class RadGridDP : RadGrid
    {  
          
    public RadGridDP()
         {
           this.MasterTableView.CommandItemSettings.ShowExportToPdfButton = true;
           
    this.MasterTableView.CommandItemSettings.ShowExportToExcelButton = true;
           this.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = false;
         }
    }

    and this script on the page consisting of the grid:
     <script type="text/javascript"><br>               
         function onRequestStart(sender, args) {
            
    if (args.get_eventTarget().indexOf("ExportToPdfButton") >= 0 || 
               args.get_eventTarget().indexOf(
    "ExportToExcelButton") >= 0|| 
               args.get_eventTarget().indexOf(
    "ExportToWordButton") >= 0 ||    
               args.get_eventTarget().indexOf(
    "ExportToCsvButton") >= 0)
               {    
                  args.set_enableAjax(
    false);<br>                   
               }               
           }
      </script>


    and it started to work. Infact custom controls can be added to MasterTableView.CommandItems via setting CommandItemTemplate. i.e.
    public class myClass:ITemplate
    {
      
    //custom buttons
    }


    am not sure, but may b the way I was doing it earlier, was wrong. 

    Reply

  • Posted on Jan 16, 2012 (permalink)

    Glad you found a solution.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > RadControls in DotNetNuke > Telerik RadGrid ExportToPDF() or ExportToExcel() not working