M ) Export Excel ( Download Control Data in Microsft Excel format )

                                                            *  Export Excel *


  •    Export excel Download a PDF FILE In Microsoft Execl format.

    Q )  How to hide extra columns in Export excel pdf

    Code = GridView1.Columns[6].Visible=false;


Step
1) select any gridview page
2) toolbox -- button(export excel)
3) paste all export excel coding in export excel button
4) StringWriter and HtmlForm select and rightclick -- resolve -- and select librarys stringwriter and htmlform        



Paste Export Excel all code on expot excel button

  string attachment = "attachment; filename=student.xls";  //name the file //student.xls can give any name(koi bhi name de skte hai)

        Response.ClearContent();

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

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

        StringWriter sw = new StringWriter();     //    Stringwriter--rightclick--resolve--using.system.IO;

        HtmlTextWriter htw = new HtmlTextWriter(sw);

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


        HtmlForm frm = new HtmlForm();            //    HtmlForm--rightclick--resolve--using.system.web.io

        GridView1.Parent.Controls.Add(frm);      //change the gridview id

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

        frm.Controls.Add(GridView1);            //change the gridview id

        frm.RenderControl(htw);

        Response.Write(sw.ToString());

        Response.End();

                       


 

Comments

Popular posts from this blog

DATA CONTROL ( Gridview , Repeater , Formview , DataList , Detailsview , Listview )

Z 5 ) MVC (Model view Controller)

Z 8 ) MVC HTMLHELPER METHOD AND ACTIONLINK (how to use css ,atrributes,style in css)