Solved

ASP.NET VB Export to Excel Exception

Posted on 2010-08-24
1
259 Views
Last Modified: 2012-05-10
When trying to use the following export to excel in my button.click event:  Any help ??? (Please don't send me to another tutorial.  I've been to about 25 of them already).  Note that the grid is in the content area page and I'm using Master Pages.  The grid renders correctly and populates the data correctly from my datasource

Response.Clear()

        ' Set the type and filename   
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
        Response.Charset = ""
        Response.ContentType = "application/vnd.xls"

        ' Add the HTML from the GridView to a StringWriter so we can write it out later   
        Dim sw As System.IO.StringWriter = New System.IO.StringWriter
        Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw)
        EmployeeGrid.RenderControl(hw)

        ' Write out the data   
        Response.Write(sw.ToString)
        Response.End()

Open in new window


I get this exception on the RenderControl call:

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

Below is my grid in asp (which loads perfectly)

 <asp:GridView ID="EmployeeGrid" runat="server" AutoGenerateColumns="False" 
        DataSourceID="ObjectDataSource1" 
        CssClass="mGrid"
        AlternatingRowStyle-CssClass="alt" >
        <Columns>
            <asp:BoundField DataField="LastName" HeaderText="LastName" 
                SortExpression="LastName" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" 
                SortExpression="EmailAddress" NullDisplayText="---" DataFormatString="<a href=mailto:{0}>{0}</a>" HtmlEncodeFormatString="false"/>
            <asp:BoundField DataField="Location" HeaderText="Location" 
                SortExpression="Location" />
            <asp:BoundField DataField="JobTitle" HeaderText="JobTitle" 
                SortExpression="JobTitle" />
        </Columns>

<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
    </asp:GridView> 

Open in new window

0
Comment
Question by:rwdMike
1 Comment
 

Accepted Solution

by:
rwdMike earned 0 total points
ID: 33513536
Ok, well, figured it out.  The example I used didn't include the need to override VerifyRenderinginServerForm

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
    End Sub
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now