1 Response.Clear(); 2 Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); 3 4 Response.Charset =""; 5 6// If you want the option to open the Excel file without saving than 7 8// comment out the line below 9 10//Response.Cache.SetCacheability(HttpCacheability.NoCache); 11 12 Response.ContentType ="application/vnd.xls"; 13 14 System.IO.StringWriter stringWrite =new System.IO.StringWriter(); 15 16 System.Web.UI.HtmlTextWriter htmlWrite =new HtmlTextWriter(stringWrite); 17 18 gridView.RenderControl(htmlWrite); 19 20 Response.Write(stringWrite.ToString()); 21 22 Response.End();
1publicoverridevoid VerifyRenderingInServerForm(Control control) 2{ 3 4// Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time. 5 6 }