Export to Excel shows an empty sheet

P

Paul D. Fox

When I run my Export to Excel, the Spreadheet is empty. Anyone know what may cause this? Here is my code:
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment;filename=" & strFileName & ".xls")


Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

Dim dg As New DataGrid

'Copy data from existing Datagrid to the new Datagrid

dg = dgExport

dg.AllowPaging = False
dg.AllowCustomPaging = False
dg.AllowSorting = False
dg.EnableViewState = False

'Lets make it a generic looking spreadsheet
dg.HeaderStyle.BackColor = Color.LightGray
dg.AlternatingItemStyle.BackColor = Color.White
dg.FooterStyle.BackColor = Color.LightGray
dg.PagerStyle.BackColor = Color.Gainsboro
dg.HeaderStyle.Font.Bold = True

dg.DataBind()
dg.RenderControl(htmlWrite)

Response.Write(stringWrite.ToString)
Response.End()

Paul
 
P

Paul D. Fox

I seemed to have found the Issue. in my Page_Load event I have...
The Page_Load event has the following:

If Not Page.IsPostBack Then
dgrdLCFDynamicReport.SelectedIndex = 0
If dgrdLCFDynamicReport.Attributes("SortExpression") Is Nothing Then
dgrdLCFDynamicReport.Attributes("SortExpression") = "Create_Date" 'Default Sort
dgrdLCFDynamicReport.Attributes("SortDirection") = "ASC"
End If
Bind_dgrdLCFDynamicReport()
End If

This prevents the ability to Export the datagrid to Excel. By Removing the If/End If statement, the Datagrid can be properly exported. Not sure if this is actually an ASP.NET error or what...

Paul
When I run my Export to Excel, the Spreadheet is empty. Anyone know what may cause this? Here is my code:
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment;filename=" & strFileName & ".xls")


Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)

Dim dg As New DataGrid

'Copy data from existing Datagrid to the new Datagrid

dg = dgExport

dg.AllowPaging = False
dg.AllowCustomPaging = False
dg.AllowSorting = False
dg.EnableViewState = False

'Lets make it a generic looking spreadsheet
dg.HeaderStyle.BackColor = Color.LightGray
dg.AlternatingItemStyle.BackColor = Color.White
dg.FooterStyle.BackColor = Color.LightGray
dg.PagerStyle.BackColor = Color.Gainsboro
dg.HeaderStyle.Font.Bold = True

dg.DataBind()
dg.RenderControl(htmlWrite)

Response.Write(stringWrite.ToString)
Response.End()

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top