Error throwing Export to excel

Posted by Abhisekjani under C# on 10/12/2012 | Points: 10 | Views : 2804 | Status : [Member] | Replies : 1
Hi
while i click on button to export griddata to excel in page load it throws the error

VerifyRenderingInServerForm(System.Web.UI.Control)': no suitable method found to override

below code i write in in my page plz help me


protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataBind();
Response.Clear();
Response.AddHeader("content-disposition"," attachment;filename=myexcelfile.xls");
Response.ContentType = "application/vnd.xls";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
AxGridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();

}
public override void VerifyRenderingInServerForm(Control control)
{

}


Thanks
Abhiek




Responses

Posted by: Megan00 on: 10/16/2012 [Member] Starter | Points: 25

Up
0
Down
Look at below code:
System.Web.UI.Control ctl=this.DataGrid1;

//DataGrid1 (you created in the windowForm)
HttpContext.Current.Response.AppendHeader
("Content-Disposition","attachment;
filename=Excel.xls");
HttpContext.Current.Response.Charset ="UTF-8";
HttpContext.Current.Response.ContentEncoding
=System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType
="application/ms-excel";
ctl.Page.EnableViewState =false;
System.IO.StringWriter tw = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();


Further consult: http://www.codeproject.com/Articles/164582/8-Solutions-to-Export-Data-to-Excel-for-ASP-NET

Never give up! Smile to the world!
http://excelcsharp.blog.com/

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response