Saturday 28 April 2012

Export To excel from gridview

   protected void btnGenerate_Click(object sender, EventArgs e)
            // Here is example code for export Gridview to excel sheet,

            Response.Clear();             // Clear the response
            // Set the type and filename
            Response.AddHeader("content-disposition", "attachment;filename =        
            Response.Charset = "";
            Response.ContentType = "application/ms-excel";
       // Add the HTML from the GridView to a StringWriter so we can write it out later 
            System.IO.StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(sw);

            // Write out the data 


        public override void VerifyRenderingInServerForm(Control control)

        //Enjoy Life as much as you can….

No comments:

Post a Comment