Datagrid to excel

P

Phil Barber

using VS2003 the following code will send data from a datagrid to an excel
sheet:
Response.Clear();
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
DataG.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

When I try this in VS2005 (using a GridView)
I get an Error on line:
DataG.RenderControl(htmlWrite);

DataG must me be placed in a form tag with runat=server.
any ideas what must be done to get this to work?
thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top