Click here to Skip to main content
15,917,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello I am making an ASP.NET web appplication..
I have one grid in my application
I also have an export button..
Now I wants that when I click on export button, then the data of the
grid should be save in .xls file..

My code is this, it bilds succed but at runtime it is not working


protected void BtnExport_Click(object sender, EventArgs e)
{
  Response.Clear();
  Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
  Response.Charset = "";
 Response.Cache.SetCacheability(HttpCacheability.NoCache);

    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();
}



public override void VerifyRenderingInServerForm(Control control) 

{ 

  

}

Its not working
Posted
Updated 15-Feb-10 3:05am
v2

I dont like the technique of writing the html and show the html in Excel.

I would definitely prefer to use the normal XLS format to export data.

May be using this :
Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^]

If you still like this technique, use
http://aspalliance.com/771[^]
 
Share this answer
 
SQL
I dont like the technique of writing the html and show the html in Excel. 

I would definitely prefer to use the normal XLS format to export data.




I didn't get that what u said..

I tried the code which u told.. it builds succed but at run time
it is not working neither showing any error
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900