Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exporting to excel

Status
Not open for further replies.

harneel

Programmer
Jan 22, 2004
7
0
0
US
hi

I'm using the stringwriter and htmltextwriter to export the data and the declaration of my button click event is

Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles btnExport.Click

i'm having an error saying "Compiler Error Message: BC30506: Handles clause requires a WithEvents variable."

seems like the code is not running at all if i remove "handles btnExport.Click" from the code.

Any ideas..
 
this is how I export from a datagrid..not sure if that's what you're doing but hey here it is....
Protected WithEvents btnExport As System.Web.UI.WebControls.Button

Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
Dim newGrid As New DataGrid()
newGrid.HeaderStyle.Font.Bold = True
newGrid.DataSource = dgClients.DataSource
newGrid.DataBind()

Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
newGrid.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
End Sub
 
hi
this time it's not giving me an eror but it's not doing anything?.... all the code is written in an .aspx file. I'm not using any .vb files.

 
har: makes sure you do a search here at Tek-Tips - there have been at least a dozen threads on this topic over the last 6 mos or so -- might find more materials there.
 
the reason I have this in there:
Dim newGrid As New DataGrid()
newGrid.HeaderStyle.Font.Bold = True
newGrid.DataSource = dgClients.DataSource
newGrid.DataBind()

is because i have sorting on my original datagrid...if you don't allow sorting you can leave that off...I'm not as familiar with coding solely on the .aspx file...

dlc
 
Hi,

i'm getting a blank page. The code seems to be running fine but i don't see anyhting on the screen.
 
do i have to convert any of hte grid columns. All i have now are the regular bound columns.
 
You don't have to convert any of the columns, but you might want to change the following line:
Response.Write(tw.ToString())
to
Response.Write(tw.ToString)

That should do it.

Hope this helps,
CHIX001
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top