For PDF:
HTML convert to PDF using itextsharp[
^]
For Excel:
protected void btnExpExcel_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Report.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataTable dt = new DataTable();
dt = (DataTable)Session["dtReport"];
gvMISReport.AllowPaging = false;
gvMISReport.DataSource = dt;
gvMISReport.DataBind();
gvMISReport.HeaderRow.Style.Add("background-color", "#FFFFFF");
for (int i = 0; i < gvMISReport.HeaderRow.Cells.Count; i++)
{
gvMISReport.HeaderRow.Cells[i].Style.Add("background-color", "#157CB0");
}
int j = 1;
foreach (GridViewRow gvrow in gvMISReport.Rows)
{
gvrow.BackColor = Color.White;
if (j <= gvMISReport.Rows.Count)
{
if (j % 2 != 0)
{
for (int k = 0; k < gvrow.Cells.Count; k++)
{
gvrow.Cells[k].Style.Add("background-color", "#EFF3FB");
}
}
}
j++;
}
gvMISReport.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}