DatagridView Export Help

Oct 24, 2008 at 11:30 AM
Hello,

Could anyone help me with the following problem I'm having. I have a datagrideview object on one of my UserControls (widgets), I need to export the datagridview to an excel format to the client pc? Here is my code I used in the past:

        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-excel";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite =
        new HtmlTextWriter(stringWrite);
        GridView1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());
        Response.End();

But because this is not done within <Form> tags its not going to work.

Does anyone have any work-around suggestions?

Regards