Re: problem exporting datagrid to excel

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Peter Bromberg [C# MVP] (pbromberg_at_yahoo.com)
Date: 03/26/05


Date: Fri, 25 Mar 2005 22:09:25 -0500

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

"Dave Bailey via DotNetMonster.com" <forum@DotNetMonster.com> wrote in
message news:44965e6eff7040f795710d82c819d339@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
> spread***.
>
> The is no other control on the datagrid so I am at a loss. Any
> suggestions
> would be appreciated.
>
> Thanks,
>
> Dave
>
> --
> Message posted via http://www.dotnetmonster.com


Quantcast