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
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