problem exporting datagrid to excel

  • Thread starter Dave Bailey via DotNetMonster.com
  • Start date
D

Dave Bailey via DotNetMonster.com

I am using the following code to export a datagrid to excel from an asp
page:

private void exportButton_Click(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
hw.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Html);
this.ClearControls(reportGrid);
reportGrid.RenderControl(hw);
hw.RenderEndTag();
Response.Write(tw);
Response.End();
}

When I run this code I only get the first column returned to the
spreadsheet.

The is no other control on the datagrid so I am at a loss. Any suggestions
would be appreciated.

Thanks,

Dave
 
P

Peter Bromberg [C# MVP]

Are you sure that calling "ClearControls" makes sense?
Try commenting it out and see what happens.
Peter
 

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