'GridView' must be placed inside a form tag with runat=server.
when export gridview to excel.
add this statement in the page, it will work.
public override void VerifyRenderingInServerForm(Control control)
{
}
how to export gridview to excel
protected void btnExportExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=myexcel.xls");
Response.ContentType = "application/vnd.xls";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}


0 Comments:
Post a Comment
<< Home