• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 633
  • Last Modified:

datagrid to excel


I am trying to export a datagrid to an excel sheet. I found this code at the following location:http://codebetter.com/blogs/darrell.norton/archive/2004/02/12/7154.aspx

 ' Set the content type to Excel
        Response.ContentType = "application/vnd.ms-excel"

        'Turn off the view state
        Me.EnableViewState = False

        'Remove the charset from the Content-Type header
        Response.Charset = String.Empty

        Dim myTextWriter As New System.IO.StringWriter
        Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter)

        'Get the HTML for the control

        'Write the HTML to the browser

        'End the response

The problem is that I have a checkbox in my datagrid and I get the following error when I run it:
Control 'dg_disp__ctl2_cbSelect' of type 'CheckBox' must be placed inside a form tag with runat=server.

If I remove the checkbox it will export the data. Does anyone know of a way that I can export the rest of the data in the grid without exporting the checkbox? I would appreciate the help. Thank you!
  • 4
  • 3
1 Solution
I've had this error myself and fot the life of me can't remeber excatly the issue.  Have a read through this.


compare with your code...must be something different.

Actually add this to your code behind.

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As

End Sub
savache27Author Commented:
Okay, I'm sorry, but where do I need to put this exactly. I tried to place it in my code behind and it said:
sub VerifyRenderingInServerForm shadows an overloadable member declared in the base class "Page". If you want to overload the base method, this method must be declared 'Overloads'.
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

make sure format the line correct eg

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
end sub
savache27Author Commented:
AWESOME!! Thank you so much!!! Now I've just got to go figure out some code to get it to only export the rows that are checked. Thanks again for the help!
Open  a new questions and I'll help with the checkbox stuff..
savache27Author Commented:
I would appreciate that! I have opened a new question called datagrid to excel checkbox. Thanks again for the previous help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now