Home All Groups Group Topic Archive Search About

problem exporting datagrid to excel

Author
25 Mar 2005 6:46 PM
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

--
Message posted via http://www.dotnetmonster.com

Author
26 Mar 2005 3:09 AM
Peter Bromberg [C# MVP]
Are you sure that calling "ClearControls" makes sense?
Try commenting it out and see what happens.
Peter

Show quote
"Dave Bailey via DotNetMonster.com" <fo***@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
> spreadsheet.
>
> 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

AddThis Social Bookmark Button