Exporting HTML Content to Excel

There are many resources out there on the web that illustrate exporting data to excel from an ASP.NET page, using the gridview control.  This is the most common approach, though the Excel approach is not limited to a GridView control (I got it to work with a ListView that rendered a complex table structure).  I found this (http://aspalliance.com/771) as one of them, but it includes an extra tidbit I was having problems with.

For some reason, my default setup had the exception "GridView does not exist in a form that defines runat="server", or something like that.  By overriding the Page's method VerifyRenderingInServerForm, this alleviates the problem.  Don't know why; this method is meant to check whether the a control exists in a form, but I don't know why a control rendered via Excel has that very problem, being the control was within a server form.  Anyway, this caused it to work.

Published Friday, May 16, 2008 2:12 AM by bmains
Filed under:

Comments

No Comments