FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Exporting Data From A Datalist To An Excel Sheet

 


umeshtangnu
I’m using this code to export data from a datagrid to an Excel sheet:

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.
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.