Response.Clear (); response.buffer = true; response.contenttype = "Application / VND.MS-Excel"; response.charset = ""; this.enableviewState = false;
System.io.stringWriter ostringwriter = new system.io.stringWriter (); system.Web.ui.htmlTextWriter OhtmlTextWriter = new system.web.ui.htmlTextWriter (OstringWriter);
DataGrid DG = New DataGrid (); DG.DataSource = getDataSource (); // Returns DataSet or DataTableDg.Database (); DG.RenderControl (OhtmlTextWriter);
Response.write (ostringwriter.tostring ());
Response.end (); if there is garbled code: response.contentencoding = system.text.encoding.utf8