How to Export Grind View data to excel.
pls send me With Examples.
How to Export Grind View data to excel?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 6, 2012, 1:19 AM EST
Please refer the below link
http://www.c-sharpcorner.com/UploadFile/DipalChoksi/exportxl_asp2_dc11032006003657AM/exportxl_asp2_dc.aspx
Thanks
Hermes Condez37 reputationPosted Mar 6, 2012, 3:13 AM EST
protected void ExportToXls_Click(object sender, EventArgs e) //On click Event of a control (button/link button/hyperlink)
{
this.DataGridView1.AllowPaging = false;
ExportGridViewToExcel(Response, this.DataGridView1, "Exported.xls");
}
public void ExportGridViewToExcel(HttpResponse response, GridView gvControl, string fileName)
{
string attachment = "";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
response.AddHeader("content-disposition", "attachment; filename=" + fileName);
response.ClearContent();
response.AddHeader("content-disposition", attachment);
gvControl.AllowPaging = false;
gvControl.DataBind();
gvControl.RenderControl(htw);
response.Write(sw.ToString());
response.Flush();
response.End();
gvControl.AllowPaging = true;
}
public override void VerifyRenderingInServerForm(Control control) // I just got this in forum just
// add this. I don't why but it will work if this is added
{
}