Solved

datagrid to excel

Posted on 2007-11-16
7
610 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

863 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

24 Experts available now in Live!

Get 1:1 Help Now