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

ExportToExcel Not Working

3 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kith
Top achievements
Rank 1
kith asked on 28 Jul 2014, 10:21 AM
Hello,

I need to create a RadGrid object dynamically and be able to export the data to excel. Below is the simple class I created. No error occurs but nothing happens. No file is being created. Am I missing something?

==============================================

Public Class MyOwnClass
        Inherits MyBaseClass
        
        Dim WithEvents ExportBillRadGrid As New RadGrid

        Protected Sub RowControlInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Init
            Page.Controls.Add(ExportBillRadGrid)
        End Sub

        Public Overrides Sub imgDL_Click(ByVal sender As Object, ByVal args As ImageClickEventArgs)
        
            Try
                ExportBillRadGrid.DataSource = SetQueryStrings()
                ExportBillRadGrid.DataBind()
                
                ExportBillRadGrid.ExportSettings.ExportOnlyData = True
                ExportBillRadGrid.ExportSettings.IgnorePaging = True
                ExportBillRadGrid.ExportSettings.OpenInNewWindow = True
                ExportBillRadGrid.ExportSettings.FileName = "Exported-Billing-Data"
                ExportBillRadGrid.MasterTableView.ExportToExcel()


            Catch ex As Exception
                Me.Page.ErrorOnPage = True
                Utils.MiscUtils.RegisterJScriptAlert(Me, "BUTTON_CLICK_MESSAGE", ex.Message)

            Finally

            End Try

        End Sub

        Private Function SetQueryStrings() As DataTable

            Dim query As String = "select * from myTable"


            Dim dt As DataTable = New DataTable()
            Dim connString As String = ConfigurationManager.ConnectionStrings("connString").ToString()
            Dim conn As SqlConnection = New SqlConnection(connString)
            Dim adapter As SqlDataAdapter = New SqlDataAdapter()
            Dim qryCmd = New SqlCommand(query, conn)

            adapter.SelectCommand = qryCmd
            adapter.Fill(dt)

            Return dt
        End Function
    End Class

==============================================

I really need your help.

Thanks!
--
Matt

3 Answers, 1 is accepted

Sort by
0
kith
Top achievements
Rank 1
answered on 29 Jul 2014, 01:39 AM
Anyone out there who can help me figure this one out? :)
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2014, 03:01 AM
Hi Kith,

I see that you are binding the Grid on some click function. Please use the Advanced Data-binding (Using NeedDataSource Event) to bind your Grid. Please note that the exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.
Export from Ajaxified Grid. Please try as suggested and check if the issue is resolved.

Thanks,
Princy
0
kith
Top achievements
Rank 1
answered on 01 Aug 2014, 02:57 PM
Thanks! It worked :)
Tags
Grid
Asked by
kith
Top achievements
Rank 1
Answers by
kith
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or