Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2007

Tip: Looking for answers? Try searching our database.

Master Page Gridview Export Excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Madison - 14 Dec 2007 22:56 GMT
Hello,

I try to export to Excel from gridview using framework2 with master page.  
Here is my coding
       Response.Clear()
       Response.AddHeader("content-disposition",
"attachment;filename=foe.xls")
       Response.ContentType = "application/vnd.xls"
       Response.Charset = ""
       Me.EnableViewState = False
       Dim sw As New System.IO.StringWriter
       Dim htmlWriter As New HtmlTextWriter(sw)
       myGrid.RenderControl(htmlWriter)
       Response.Write(htmlWriter.ToString)
       Response.End()
When I ran it, I got the message said "Control 'ctl00_BodyContent_myGrid' of
type 'GridView' must be placed inside a form tag with runat=server". I have
tried many search but nothing it works yet.
Any solution to this message.
Thanks.
Walter Wang [MSFT] - 17 Dec 2007 02:01 GMT
Hi,

This error is because by default the Page class is checking if the control
is put into a server-side form before rendering it in its
VerifyRenderingInServerForm() method. The workaround is to derive from Page
class and override this method to bypass the checking:

#GridViewGuy
http://www.gridviewguy.com/ArticleDetails.aspx?articleID=86

Hope this helps.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Madison - 17 Dec 2007 14:35 GMT
Hi Walter,

Thank you for your reply. I have tried calling

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

The article did not mention where should this overrides call and what I have
to pass  with parametere. I just have the code and tried to run, I still get
the message say

Control 'ctl00_BodyContent_myGrid' of type 'GridView' must be placed inside
a form tag with runat=server.

and the error point to MyBase.VerifyRenderingInServerForm(control)

Thank you for your advise.

> Hi,
>
[quoted text clipped - 18 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 19 Dec 2007 02:18 GMT
Hi Madison,

Sorry for not clarifying the code previously.

You need to create a custom class that inherits from System.Web.UI.Page and
override this method in this custom class. Then you change your WebForm to
inherit from this custom class instead of System.Web.UI.Page, you can do
this in the code-behind of your WebForm.

Hope this helps.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Madison - 19 Dec 2007 21:43 GMT
Hi Walter,

Thank you for your reply.
I end up with create the second gridview on code-behind (the display
gridview needs sorting and paging) and found the error with my coding. Here
is the way I did

       Dim ds As DataTable = ViewState("report")
       Dim sw As New StringWriter
       Dim htw As New HtmlTextWriter(sw)
       Dim dg As New GridView
       dg.DataSource = ds
       dg.DataBind()
       dg.RenderControl(htw)

       Response.Write(sw.ToString)
       Response.End()

I'm not sure that using viewstate to hold dataset vs call stored procedure
to retrieve new dataset which one better.

> Hi Madison,
>
[quoted text clipped - 17 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 20 Dec 2007 08:01 GMT
Hi Madison,

Thanks for your update. Looks like I had previously misunderstood your
question.

For question about holding dataset in ViewState, usually this is a
tradeoff. I think you just need to compare both approaches' pro and con and
decide which one is better according to your specific configuration:

In ViewState:
Pro: avoid repeatedly querying database
Con: increase page size and may cause performance issue if your users are
on a slow connection

Querying database everytime:
Pro: Page size is reduced and loads faster
Con: database server may become a bottleneck if it's already on high-load

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Ettore Cefalà - 22 Dec 2007 18:47 GMT
To get a real XML or XLSX export to Excel you should try
http://www.gridviewtoexcel.com; it works also with very large number of
records (even though you can perform large export in HTML from your
server, it's really painful to open them with Excel); it can compress
the exported files to be  and send them via email.

Regards

Ettore

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.