Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView to Excel error

Reply
Thread Tools

GridView to Excel error

 
 
David
Guest
Posts: n/a
 
      10-20-2006
Using ASP.Net 2.0 and I have identical code for exporting a GridView to
Excel in 2 web sites. One works fine and the 2nd one gives me the error
"RegisterForEventValidation can only be called during Render();"

This error occurs on the line that reads "gv.RenderControl(hw)"

Below is my code. Can anybody give me a clue? Thanks.

Sub SendToExcel(ByVal Source As Object, ByVal E As EventArgs)

Dim gv As GridView = SearchResultsGridView

If gv.Rows.Count.ToString + 1 < 65536 Then


gv.AllowPaging = False

gv.AllowSorting = False

If txtSearchText.Text <> "" Then

SqlvwFileSearch.SelectCommand = txtSearchText.Text

End If

gv.DataBind()


Dim tw As New StringWriter()

Dim hw As New System.Web.UI.HtmlTextWriter(tw)

Response.Clear()

Response.ContentType = "application/vnd.ms-excel"

Response.AddHeader("content-disposition", "attachment;filename=search.xls")

Response.Charset = ""

EnableViewState = False

gv.RenderControl(hw)

Response.Write(tw.ToString())

Response.End()

'gv.AllowPaging = True

gv.AllowSorting = True

gv.DataBind()

lblErrorMsg.Text = ""

Else

lblErrorMsg.Text = "Too many rows - Export to Excel not possible"

End If

End Sub


Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)

End Sub

David


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
export gridview to excel format error JohnE ASP .Net 6 10-09-2010 09:33 AM
GridView to Excel then Excel to database table. mohaaron@gmail.com ASP .Net 0 11-06-2007 06:40 PM
Problem with Excel reports ::::Excel 2003 Migration To Excel 2007 =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?= ASP .Net 15 10-24-2007 01:34 PM
Export GridView to Excel Error =?Utf-8?B?bWFuaWthMDI=?= ASP .Net 3 02-26-2007 02:47 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM



Advertisments