I am trying to use the GridView's rendercontrol method to export the grid into an Excel worksheet. This code works with a DataGrid, but not with the new GridView control. When I try to execute the code, I get the following error even though the control is placed
within a form runat=server tag:
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Any ideas? This works fine with the DataGrid but does not with GridView
You can make this scenario work by overriding Page.VerifyRenderingInServerForm. See
this for more information. This will cause your Excel scenario to work, but we don't really support calling RenderControl to do things like changing the GridView rendering, etc., and functionality like command buttons shouldn't be expected to work in this
sort of scenario.
This posting is provided "AS IS" with no warranties, and confers no rights.
1. Why does a DataGrid work and a GridView doesn't? I think I used that before without problems.
2. What's the point of the RenderControl method on the GridView if it doesn't work?
trent
Member
60 Points
12 Posts
Export Gridview to Excel
Jul 13, 2005 06:08 PM|LINK
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
Any ideas? This works fine with the DataGrid but does not with GridView
************************
Response.Clear()
Response.ContentType = "application/ms-excel"
Response.Charset = ""
Page.EnableViewState = False
Response.AddHeader("Content-Disposition", "attachment;filename=test.xls")
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
GridView1.RenderControl(hw)
Response.Write(tw.ToString)
Response.End()
irinelc
Participant
1070 Points
214 Posts
AspNetTeam
Re: Export Gridview to Excel
Jul 15, 2005 06:42 PM|LINK
Hope this helps
Irinel
Inspire
Member
10 Points
2 Posts
Re: Export Gridview to Excel
Jul 16, 2005 05:01 AM|LINK
I had the same issues. Is there any resoloution?
sumon1234
Member
10 Points
2 Posts
Re: Export Gridview to Excel
Jul 17, 2005 12:57 PM|LINK
ninatang
Member
575 Points
115 Posts
AspNetTeam
Re: Export Gridview to Excel
Jul 19, 2005 01:38 AM|LINK
ersheido
Member
448 Points
117 Posts
Re: Export Gridview to Excel
Jul 25, 2005 11:29 PM|LINK
I still don't understand:
1. Why does a DataGrid work and a GridView doesn't? I think I used that before without problems.
2. What's the point of the RenderControl method on the GridView if it doesn't work?
ninatang
Member
575 Points
115 Posts
AspNetTeam
Re: Export Gridview to Excel
Jul 26, 2005 12:49 AM|LINK
sumon1234
Member
10 Points
2 Posts
Re: Export Gridview to Excel
Jul 27, 2005 01:54 PM|LINK
Could you paste the success code for me to learn?Thanks.
I want to know the way about exporting gridview to excel.
ninatang
Member
575 Points
115 Posts
AspNetTeam
Re: Export Gridview to Excel
Jul 27, 2005 05:10 PM|LINK
End Sub
You just need to add that to the existing code (which someone has already posted above).
azamsharp
All-Star
24244 Points
4612 Posts
MVP
Re: Export Gridview to Excel
Jul 27, 2005 05:39 PM|LINK
http://gridviewguy.com/ArticleDetails.aspx?articleID=86
HighOnCoding