just paste it into your .cs file and change according to your requirement
This if for Excel and word . choose which is sutaible for you.
protected void ImgExcel_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=SupplierList.xls");
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter WriteItem = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlText = new HtmlTextWriter(WriteItem);
GrvMfDetails.Columns[9].Visible = false;
GrvMfDetails.RenderControl(htmlText);
Response.Write(WriteItem.ToString());
Response.End();
}
protected void ImgWord_Click(object sender, ImageClickEventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=SupplierList.doc");
Response.ContentType = "application/vnd.word";
System.IO.StringWriter WriteItem = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlText = new HtmlTextWriter(WriteItem);
GrvMfDetails.Columns[9].Visible = false;
GrvMfDetails.RenderControl(htmlText);
Response.Write(WriteItem.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
// this part is just get data export to excel.
}
Thanks
This will help you