Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

datagrid to excel

Posted on 2007-11-16
7
Medium Priority
?
621 Views
Last Modified: 2011-09-20
Hi,

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
        dg_disp.RenderControl(myHtmlTextWriter)

        'Write the HTML to the browser
        Response.Write(myTextWriter.ToString())

        'End the response
        Response.End()

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!
0
Comment
Question by:savache27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:skiltz
ID: 20301575
I've had this error myself and fot the life of me can't remeber excatly the issue.  Have a read through this.

http://support.microsoft.com/default.aspx?scid=kb;en-us;317719

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

Thanks,
Matthew
0
 
LVL 7

Expert Comment

by:skiltz
ID: 20301606
Actually add this to your code behind.

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
Control)

End Sub
0
 

Author Comment

by:savache27
ID: 20301644
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'.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Accepted Solution

by:
skiltz earned 2000 total points
ID: 20301667
make sure format the line correct eg


Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
end sub
0
 

Author Comment

by:savache27
ID: 20301710
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!
0
 
LVL 7

Expert Comment

by:skiltz
ID: 20301730
Open  a new questions and I'll help with the checkbox stuff..
0
 

Author Comment

by:savache27
ID: 20301759
I would appreciate that! I have opened a new question called datagrid to excel checkbox. Thanks again for the previous help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

636 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