savache27
asked on
datagrid to excel
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.HtmlTextWrit er(myTextW riter)
'Get the HTML for the control
dg_disp.RenderControl(myHt mlTextWrit er)
'Write the HTML to the browser
Response.Write(myTextWrite r.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!
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.HtmlTextWrit
'Get the HTML for the control
dg_disp.RenderControl(myHt
'Write the HTML to the browser
Response.Write(myTextWrite
'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!
Actually add this to your code behind.
Public Overrides Sub VerifyRenderingInServerFor m(ByVal control As
Control)
End Sub
Public Overrides Sub VerifyRenderingInServerFor
Control)
End Sub
ASKER
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 VerifyRenderingInServerFor m shadows an overloadable member declared in the base class "Page". If you want to overload the base method, this method must be declared 'Overloads'.
sub VerifyRenderingInServerFor
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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..
ASKER
I would appreciate that! I have opened a new question called datagrid to excel checkbox. Thanks again for the previous help!
http://support.microsoft.com/default.aspx?scid=kb;en-us;317719
compare with your code...must be something different.
Thanks,
Matthew