I am using two grids in a page and I want to export those two grids on export to excel. I use the below code to export a single gridview and it works fine. Can anyone suggest me on how to achieve export for two grid views.
protected void btnExport_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename= {0}", "Reports.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
//Change the Header Row back to white color
GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");
//Applying stlye to gridview header cells
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
GridView1.HeaderRow.Cells[i].Style.Add("background-color", "#aaaaaa");
}
GridView1.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
Sagar PardeshiPosted Jan 20, 2014, 2:39 AM
Follow below Code it's working for multiple grid view export to excel
Report
" + DateTime.Now.ToString("d") + "
Eugene MontesPosted Mar 24, 2015, 4:11 AM
So instead you will need to generate a real PDF file, there are few ways you can do that and one of them is with this .NET library for excel files.
It can enable you to convert the HTML content (like your sw.ToString()) into an Excel file in .net, but also you can convert the Excel content into a PDF file in .net.
And last you can directly export your Excel and/or PDF files to ASP.NET's client.
Vignesh KumarPosted Jan 20, 2014, 3:11 AM
It worked great. Is there any possible way to do it for pdf like excel.