Export GridView to Excel

           string attachment = "attachment; filename=registration.xls";

        Response.ClearContent();

        Response.AddHeader("content-disposition", attachment);

        Response.ContentType = "application/ms-excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter htw = new HtmlTextWriter(sw);

        HttpContext.Current.Response.Write("<br>");

        HtmlForm frm = new HtmlForm();


        GridView1.Parent.Controls.Add(frm);

        frm.Attributes["runat"] = "serve";

        frm.Controls.Add(GridView1);

        frm.RenderControl(htw);


        Response.Write(sw.ToString());

        Response.End();

Comments

Popular posts from this blog

Parameter Query

Final Project

Grid View Paging