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

Radgrid Export to Excel - out of memory exception error

1 Answer 362 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raja Rajeswari Mohan Venkataraman
Top achievements
Rank 1
Raja Rajeswari Mohan Venkataraman asked on 04 May 2012, 09:07 PM
Hi,

I am using telerik radgrid and binding the data to it. I have a separate button named 'Export To Excel'. When I click on that button it needs to

export all the records from the grid to excel. For huge datasets when I try to export it gives me out of memory exception error.

Is there anyway I can capture this exception error in my web page.

The function that I use to export to excel is below. I would like to capture that exception in the below function.

Could you please help me to achieve this.

Private Sub btnPrintAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrintAll.Click
        Try
            Dim radGridExport As RadGrid
            If Me.Parent.Page.Title = "Database Circle Search" Then
                strCallingPage = "CIR"
            ElseIf Me.Parent.Page.Title = "Database Search" Then
                strCallingPage = "SEA"
            End If

            If Not Session("MILUSER") Is Nothing Then
                IsMilUser = CType(Session("MILUSER"), Boolean)
            Else
                IsMilUser = False   ' If object not in session then make it false
            End If

            Dim blnfromSrchUsrCtl As Boolean = True
            Dim blnfromCustGrid As Boolean = False
            Dim blnFromPrintAll As Boolean = True
   

            Dim startTick As Long = DateTime.Now.Ticks
            Dim endTick As Long
            Dim tick As Long
            Dim milliseconds As Long
            Dim microseconds As Long

            strColOrder = ViewState("Column Order")

            If Me.Parent.Page.Title = "Database Search" Then
                Dim objPage As SearchDB
                objPage = CType(MyBase.Page, Page)
                If Not objPage Is No
                    objPage.CustomizeGridColumns(strColOrder, blnfromSrchUsrCtl)
                Else
                    Exit Sub
                End If
            ElseIf Me.Parent.Page.Title = "Database Circle Search" Then
                 If Not IsMilUser Or Not IsEASearch Then
                    Dim objPage As CircleSearchDB
                    objPage = CType(MyBase.Page, Page)
                    If Not objPage Is Nothing Then
                        objPage.CustomizeGridColumns(strColOrder, blnfromSrchUsrCtl)
                    Else
                        Exit Sub

                    End If
                End If
            End If

            radGridExport = CType(Me.FindControl("grdExport"), RadGrid)
            If IsMilUser And strCallingPage = "CIR" And IsEASearch Then
                radGridExport.ExportSettings.IgnorePaging = True
                radGridExport.ExportSettings.OpenInNewWindow = True
                radGridExport.ExportSettings.ExportOnlyData = True
                radGridExport.MasterTableView.ExportToExcel()
            Else
              
                grdResult.MasterTableView.GetColumn("SEL").Display = False
                grdResult.ExportSettings.IgnorePaging = True
                grdResult.ExportSettings.OpenInNewWindow = True
                grdResult.ExportSettings.ExportOnlyData = True
                grdResult.MasterTableView.ExportToExcel()

                If grdResult.MasterTableView.GetColumn("FRQ").Visible = True Then
                    grdResult.MasterTableView.GetColumn("FREQ").Visible = True
                Else
                    grdResult.MasterTableView.GetColumn("FREQ").Visible = False
                End If
             

            End If
          
        Catch ex As Exception
            AFMCommonUtils.LogError(CType(Me.Session("User"), AFMBusinessLogicLayer.UserBL).USERNAME, "UsrSearchResult", "btnPrintAll_Click", ex.Message, ex.StackTrace)
            ClearModuleTracker()
            Response.Redirect("~/ErrorDisplay.aspx")
        End Try
    End Sub

 

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 May 2012, 06:07 AM
Hello,

Please check "Exporting a large amount of data" in below link.
http://www.telerik.com/help/aspnet-ajax/grid-export.html

//OR

Unfortunately there is little that can be done when trying to export large amounts of data. You should have in mind that when IgnorePaging is set to true, RadGrid instance will be bound to all of the 5000 records which is quite memory consuming. Exporting and storing such large amount of data in session variable will cause scalability problem. I can suggest you either to consider decreasing the amount of data or export only the current page by setting the IgnorePaging option to 'false'.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Raja Rajeswari Mohan Venkataraman
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or