I’m using this code to export data from a datagrid to an Excel sheet:
And this is working fine.
But now I want to do same with a datalist and thus I changed RenderControl line thus:
DataList1.RenderControl(oHtmlTextWriter);
Yet when Excel sheet is showing on screen, all data are displayed in one simple column “A”, with one row for each data in datalist.
Does somebody know how can I attain it work as I did as datagrd (each column in datalist into its respective column in Excel)?
I’ll appreciate your suggestions.
| Code: |
| Response.Clear();
Response.Buffer= true; Response.ContentType = "application/vnd.ms-excel"; Response.AddHeader("Content-Disposition", "inline;filename=Clientes.xls"); Response.Charset = ""; this.EnableViewState = false; System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); DataGrid1.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.End(); |
And this is working fine.
But now I want to do same with a datalist and thus I changed RenderControl line thus:
DataList1.RenderControl(oHtmlTextWriter);
Yet when Excel sheet is showing on screen, all data are displayed in one simple column “A”, with one row for each data in datalist.
Does somebody know how can I attain it work as I did as datagrd (each column in datalist into its respective column in Excel)?
I’ll appreciate your suggestions.
