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

RadGrid Export to Excel with RadAjaxPanel

10 Answers 341 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Miller
Top achievements
Rank 1
Dave Miller asked on 25 Feb 2010, 08:00 PM
I have a project that is coming to its conclusion of the next day or so.  The last component of the project benefited greatly by implementing Telerik's Ajax.  I wrapped my project in a RadAjaxPanel and all worked incredibly well.... except my export to excel class.  I reworked all with RadGrid in hopes that it would work seamlessly.  It looks great but I get no response from the button that executes the RadGrid export to excel function.  The app hesitates briefly and than returns control to the user.  I tried just using the RadAjaxManager and the wheels fell off of my MultiView views.  I have very limited exposure to Telerik and have spent the last two days searching for specific code on how to handle this.  Could you please point me to code that would show this in action?  I am coding in VB (VS2005).  Another simpler question is how do I left justify the RadGrid.MasterTableView Caption?
Thanks very much

10 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 25 Feb 2010, 09:34 PM
Hello Dave,

The first problem can be easily solved with a few lines of JavaScript:
<script type="text/javascript">
    function requestStart(sender, args)
    {
        if (args.get_eventTarget().indexOf("btnExport") >= 0)
            args.set_enableAjax(false);
    }
</script>
 
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="requestStart">
    <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" />
    <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
        <%--...--%>
    </telerik:RadGrid>
</telerik:RadAjaxPanel>

You can set the desired alignment to the caption using its CSS class:
<style type="text/css">
    .rgCaption
    {
        text-align: left;
    }
</style>

Note that the exported file won't be affected until you inject the CSS code in the output:
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    string myClass = ".rgCaption { text-align: left; }";
    string cssStyle = String.Format("<style type='text/css'>{0}</style>", myClass);
    e.ExportOutput = e.ExportOutput.Replace("<head>", "<head>" + cssStyle);
}

Protected Sub RadGrid1_GridExporting(source As Object, e As GridExportingArgs) Handles RadGrid1.GridExporting
    Dim myClass As String = ".rgCaption { text-align: left; }"
    Dim cssStyle As String = String.Format("<style type='text/css'>{0}</style>", myClass)
    e.ExportOutput = e.ExportOutput.Replace("<head>", "<head>" + cssStyle)
End Sub

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.
0
Dave Miller
Top achievements
Rank 1
answered on 26 Feb 2010, 02:13 PM
Daniel, Thank you for the very prompt response.  This did in fact resolve the problems that I knew I had. Now, during testing, I have found a few problems that I didn't know I had.  I have set paging to 50 per page. Requests for the next page result in no data returned.  Also "IgnorePaging='true'" results in "Object reference not set to an instance of an object. " on export.  I have worked around this by just eliminating paging and displaying all results to the grid.  The problem that I have not be able to work around yet is the fact that larger requests that may take 1 to 5 minutes (5000 to 10000 rows) result in either a hung browser or "Sys.WebForms.PageRequestManagerTimoutException: The server request timed out." while attempting to populate the grid.  These pages returned with no issues pre Ajax.  Any help on this would be greatly appreciated.  I may need to back out all Ajax functionality for my release next week but I would like to work this out and perhaps apply a post release fix.
Thanks again,
Dave
0
Dave Miller
Top achievements
Rank 1
answered on 26 Feb 2010, 02:32 PM
Daniel,  I may have resolved part of my more pressing problem regarding the timeout. Unfortunately in my searching I only used "PageRequestManagerTimoutException" which didn't yield any helpful results.  Shortly after my last post I searched on the full error "Sys.WebForms.PageRequestManagerTimoutException: The server request timed out."  and found the AsyncPostBackTimeout parameter. I no longer get the timeout error.  Now after several minutes the grid begins to display but than results in a javascript error referring to not enough space.  If I could address my paging issue this may go away but is there something else I need to do to address SQL queries that are slow to response and return over 5000 rows?
Thanks
0
Dave Miller
Top achievements
Rank 1
answered on 26 Feb 2010, 02:33 PM
Daniel,  I may have resolved part of my more pressing problem regarding the timeout. Unfortunately in my searching I only used "PageRequestManagerTimoutException" which didn't yield any helpful results.  Shortly after my last post I searched on the full error "Sys.WebForms.PageRequestManagerTimoutException: The server request timed out."  and found the AsyncPostBackTimeout parameter. I no longer get the timeout error.  Now after several minutes the grid begins to display but than results in a javascript error referring to not enough space.  If I could address my paging issue this may go away but is there something else I need to do to address SQL queries that are slow to response and return over 5000 rows?
Thanks
0
Daniel
Telerik team
answered on 26 Feb 2010, 03:10 PM
Hello Dave,

Judging by your explanation, this is databinding-related problem. You could sidestep the issue if you use advanced data-binding with NeedDataSource.
Advanced Data-binding help topic
Advanced Data Binding demo

Let me know whether this helps.

Best 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.
0
Dave Miller
Top achievements
Rank 1
answered on 26 Feb 2010, 05:14 PM
If tried to follow this code and have not had much luck.  I placed a break point in the 

RadGrid1_NeedDataSource Sub.  I also placed the OnNeedDataSource="RadGrid1_NeedDataSource" in the radgrid paramters.  The sub does not seem to fire.  Is there any chance that I need to disable ajax on the next page button as I did earlier in the post for the export button?

0
Daniel
Telerik team
answered on 26 Feb 2010, 06:21 PM
Hello Dave,

This is unlikely to be related to AJAX - it seems like a databinding issue to me. May I ask you to attach a sample project to a formal support ticket so I can examine it on my end? This way I will be able to provide more to-the-point answer.

Best 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.
0
Dave Miller
Top achievements
Rank 1
answered on 26 Feb 2010, 08:02 PM
Daniel,
I really appreciate your prompt assistance.  Given my current lack of knowledge of the Telerik suite and my required timeline I will need to change course a bit.  Fortunately a piece of information that you gave me early on will help me keep most of my application in tact.  I moved away from the GridView when I ran into problems with my export class.  This problem was the result of wrapping the MultiView in a RadAjaxPanel.  Your hint about using client side script to disable ajax on specific buttons has allowed me to revert to the GridView for now and leave all my other ajax aware controls in place.  I'm sure my next project will benefit from ajax and you will be hearing from me again.  Thank you.
Dave
0
nick chance
Top achievements
Rank 1
answered on 01 Nov 2012, 01:47 PM
Many thanks Daniel for a perfect explanation. This worked for me (once I'd worked out the name of the Excel button was "ExportToExcelButton"). Very many thanks Daniel, much obliged - Nick C. 

 

0
Perumal
Top achievements
Rank 1
answered on 04 Nov 2015, 09:49 AM

Hi Team,

 Am getting the issue when I place my radgrid control inside the radajaxpanel. I have enabled the ShowExportToExcelButton="true" in the radgrid.so When I click export to excel getting the javascript error.pls find the below error

" JavaScript runtime error: Unable to get property 'Cols' of undefined or null reference telerik export to excel "

Any solution pls. its urgent.

 

Tags
Grid
Asked by
Dave Miller
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Dave Miller
Top achievements
Rank 1
nick chance
Top achievements
Rank 1
Perumal
Top achievements
Rank 1
Share this question
or