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

Export-to-Excel button within the toolbar

8 Answers 283 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 05 May 2009, 10:21 AM
Hi

I would like to place my Export-to-Excel button within the toolbar.

This button should be defined as a synchronous postback trigger for my update panel.
The button is placed within CommandItemTemplate tags.

My problem is that the concept that has worked with other asp.net controls does not seem to work with RadGrid.

<asp:PostBackTrigger ControlID="myRadGrid$btnExport" />
In this type of declaration the error message I receive is the following:

A control with ID 'myRadGrid$btnExport' could not be found for the trigger in UpdatePanel 'UpdatePanel1'.


Can you please give me some suggestion?

8 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 06 May 2009, 05:05 AM
Hello Peter-

If you inspect the rendered Grid, you'll see that the btnExport ID is actually much more nested because it is rendered in a template container. That makes it difficult to target with this syntax.

 A better approach may be to simply use the RadGrid as your PostBackTrigger. Due to event bubbling, the command fired from the command item will cause the Grid to trigger your postback event. You can then handle the OnItemCommand grid event on the server and use a CommandName to detect when your export button has been clicked. Check out this page in the docs for more info on command bubbling:

http://www.telerik.com/help/aspnet-ajax/grdcommandreference.html

Hope this helps.

-Todd
0
Peter
Top achievements
Rank 1
answered on 06 May 2009, 06:52 AM
the btnExport ID is actually much more nested because it is rendered in a template container

There is templating in a lot of ASP.NET controls (such as FormView, GridView, etc.) where the ParentControlID$ControlWithinTemplateID formula works properly for declarative targeting.

This is why I am missing this.

use the RadGrid as your PostBackTrigger

I can't, because in this case I will lose the AJAX functionality provided by the grid.
0
Todd Anglin
Top achievements
Rank 2
answered on 06 May 2009, 03:51 PM
I see. It sounds like you're simply trying to enable "Export from an Ajaxified Grid."

If that's the case, there are a few help topics prepared that can assist you with this task:

DOCS: Export from Ajaxified Grid

CODE: Export Grid Content to Excel with Ajax Enabled

Take a look at the approaches outlined there and let me know if they help you solve your problem. I will also look deeper at the template control targeting syntax and try to figure out why it's not working as expected.

-Todd
0
Peter
Top achievements
Rank 1
answered on 07 May 2009, 02:59 PM

These documents describe that Excel exporting only works with synchronous postbacks.
I understand this.

My problem is only connected with the template control targeting syntax.

0
Accepted
Todd Anglin
Top achievements
Rank 2
answered on 07 May 2009, 04:57 PM
Hello Peter-

Sorry for the confusion. I was fairly certain you already understood the need for PostBacks based on your approach with the PostBackTrigger. What you should find, however, is that in the linked resources there is guidance showing you how to enable a button in a CommandItemTemplate to fire a PostBack event in a ajaxified RadGrid. Specifically, you can find the relevant code snippet here:


Essentially, you handle the OnItemCreated event of the RadGrid and implement code like this:

if (e.Item is GridCommandItem)   
{   
            Button btncmd = (e.Item as GridCommandItem).FindControl("btnExcel"as Button;   
            ScriptManager1.RegisterPostBackControl(btncmd); 

Hope that helps.

-Todd
0
Peter
Top achievements
Rank 1
answered on 09 May 2009, 10:05 AM
Thanks.

Using this last approach it works now.
0
Atul
Top achievements
Rank 1
answered on 18 Jun 2010, 04:43 PM
Hi,
I am facing the same issue :(. I have already gone through the same link ans applied it However it gives me exception on the line mentioned below:

ScriptManager1.RegisterPostBackControl(btncmd);

It gives me exception as it is not able to recognize the control.  The error I get is that find no control.
I have used Commanditemtemplate and Itemcreated events and followed the same procedure.My data grid lies in the asp: update panel..

A help wd b greatful as I am stuck with this code for last 5 days .


Thanks,
Atul

0
Daniel
Telerik team
answered on 21 Jun 2010, 09:53 PM
Hello Atul,

Please make sure that the ID of your button matches the argument, passed to the FindControl method in the ItemCreated event handler.
Button btncmd = (e.Item as GridCommandItem).FindControl("THE_ID_OF_YOUR_BUTTON") as Button;

Regards,
Daniel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Peter
Top achievements
Rank 1
Atul
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or