Export To Excel GridView with Css
protected override void Render(HtmlTextWriter writer)
{
if (Page != null)
{
if (bExport)
{
Grdshow.Visible = true;
this.bExport = false;
Page.Response.Clear();
Page.Response.Buffer = true;
Page.Response.ContentType = "application/ms-excel";
Page.Response.AddHeader("content-disposition", "attachment; filename=Report" + DateTime.Now + ".xls");
Page.Response.Charset = "UTF-8";
DateTime ct = DateTime.Now;
string currentdate = Convert.ToString(ct);
HttpContext.Current.Response.Write("<b><h1 style='Text-align:left; padding-left:65px; color: #008000; font-weight: bold; font-style: normal; font-size: large'>Amex Report</b></h1>");
this.EnableViewState = false;
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
Grdshow.RenderControl(htw);
Page.Response.Write(sw.ToString() + "<br/><br/><b>Report Date : " + currentdate + "</b>");
Page.Response.End();
}
}
base.Render(writer);
}
Button Click Event
//Export to excel button Click event
protected void btnexcel_Click(object sender, EventArgs e)
{
this.bExport = true;
}
Comments
Post a Comment