Excel Download

ashutosh9910

Freshman
Joined
May 13, 2005
Messages
44
Visual Basic:
Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", "attachment; filename=UserList.xls; sheet=Sheet2")
        Response.Charset = ""
        Me.EnableViewState = False
        Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
        Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
        dgSearchResult.RenderControl(oHtmlTextWriter)
        Response.Write(oStringWriter.ToString())
        Response.End()

The original code I got from this very firm and I modified it to the one above.
Now the problem is with Paging Enabled, it only saves the excel file with the current page recods.

Is there a way I could go about getting all the records in the excel file without them being displayed on the DataGrid


Thanks
Ashutosh
 
bri189a said:
Have a function that gets all records before performing your excel writing code.


Yes, but it is rendering data from the Data Grid and not from any data set, which shows only one page at a time.
I am quite new to ASP.NET and to .NET for that matter. so plz excuse me if I am wrong


Ashutosh
 
Loop thru your dataset and build a tab delilimted string, then write it to your stream with the .xls file extension. I have never figured out how to write a xls from a datagrid without all the formatting junk that gets carried over from the html.
 
Back
Top