protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page); scriptManager.RegisterPostBackControl(this.btnextract); ScriptManager scriptManager1 = ScriptManager.GetCurrent(this.Page); scriptManager1.RegisterPostBackControl(this.btnpostsap); } protected void btnextract_Click(object sender, EventArgs e) { if(btnextract.Text == "Extract Data") { Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Distribution.xls")); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw = new System.IO.StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gridview1.AllowPaging = false; gridview1.HeaderRow.Font.Bold = true; gridview1.HeaderRow.Height = 25; gridview1.Columns[0].Visible = false; gridview1.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } } protected void btnpostsap_Click(object sender, EventArgs e) { if(btnpostsap.Text == "Sync Data") { Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "SyncSapData.xls")); Response.ContentType = "application/ms-excel"; System.IO.StringWriter sw1 = new System.IO.StringWriter(); HtmlTextWriter htw1 = new HtmlTextWriter(sw1); gridview2.AllowPaging = false; gridview2.Visible = true; gridview2.RenderControl(htw1); Response.Write(sw1.ToString()); Response.End(); } } public override void VerifyRenderingInServerForm(Control control) { /*Tell the compiler that the control is rendered explicitly by overriding the VerifyRenderingInServerForm event.*/ }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)