Solved

datagrid to excel

Posted on 2007-11-16
7
606 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Library to convert HTML to PDF. 8 46
System32Int Error 8 44
ASP.NET reading ATOM 2 27
Different Delete Messages 7 23
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

11 Experts available now in Live!

Get 1:1 Help Now