Solved

datagrid to excel

Posted on 2007-11-16
7
616 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 7

Accepted Solution

by:
skiltz earned 500 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

695 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