protected void btnExport_Click(object sender, EventArgs e) { if (lblMsg.Visible == true) { Response.Redirect("~/Reports.aspx"); } Response.ClearContent(); Response.AppendHeader("content-disposition", "attachment;filename=FirstExport.xls"); Response.ContentType = "application/excel"; StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter); gridName.AllowPaging = false; gridName.DataBind(); gridName.HeaderRow.Style.Add("background-color", "#FFFFFF"); foreach (TableCell tableCell in gridName.HeaderRow.Cells) { tableCell.Style["background-color"] = "#A55129"; } foreach (GridViewRow gridViewRow in gridName.Rows) { gridViewRow.BackColor = System.Drawing.Color.White; foreach (TableCell gridViewRowTableCell in gridViewRow.Cells) { gridViewRowTableCell.Style["background-color"] = "#FFF7E7"; } } gridName.RenderControl(htmlTextWriter); Response.Write(stringWriter.ToString()); Response.End(); gridName.AllowPaging = true; }
gridName.DataBind();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)