In this web programming tutorial we will learn that how we can export grid view's Data into an excel sheet in asp.net using c#.
protected void BtnExport_Click1(object sender, ImageClickEventArgs e) { string attachment = "attachment; filename=Contacts.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); GridView1.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }
No comments:
Post a Comment