Export dataset to Excel
Okey.. i've seen many topics about this issue, and my problem is not exactly hoe to export the dataset, my problem is that i've created a page which exports my dataset to an excel, but the issue is that I user many typed datasets, and I store the dataset in a session and I convert it in the excel page (the code will explain it)
protected void Page_Load(object sender, EventArgs e)
{
//printXLS();
DataSet ds = (DataSet)Session["ds"];
GridView1.DataSource = ds;
GridView1.DataBind();
}
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
// If you want the option to open the Excel file without saving than
// comment out the line below
// Response.Cache.SetCacheability(HttpCacheability.No Cache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
as you can c in the page load i convert the session to dataset, which causes my probelm, I need a way to convert the session to it's relative dataset .. i believe it's undoable, but I'm open to any new iseas :)
Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
__________________
Nothing is impossible. The impossible only takes longer. \"Digital Fortress, Dan Brown\"
|