Overblog Follow this blog
Edit post Administration Create my blog
Balavardhan Reddy Narani

Export Gridview data to Excel

February 18 2010 , Written by Balavardhan Reddy Published on #ASP.Net

i)  Get the Data from the Database and Bind it to the Gridview
ii) Set Gridview Allowpaging property to "False"

Write the below code to export the entire Gridview data to Excel sheet


 private void ExportGridView()
        {
                string style = @"<style> .text { mso-number-format:\@; } </style> ";
                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);
          
                // Create a form to contain the grid
                HtmlForm frm = new HtmlForm();
                VerificationTrackingGridView.Parent.Controls.Add(frm);
                frm.Attributes["runat"] = "server";
                frm.Controls.Add(VerificationTrackingGridView);
                frm.RenderControl(htw);

                Response.Write(style);
                Response.Write(sw.ToString());
                Response.End();

        }

Share this post

Repost 0

Comment on this post

buckle 02/17/2012 16:02



Muay Thai 01/14/2012 18:48


Good content, thanks.

Muay Thai 01/14/2012 18:44


Thanks for the code mate.

fiona 04/14/2011 09:59



Wholesale Gucci Handbags
Wholesale Chanel Handbags
Wholesale D&G Handbags
Wholesale Coach Wallets
Wholesale LV Wallets
Wholesale Gucci Wallets
Wholesale Chanel Wallets
Wholesale LV Sunglasses
Wholesale Gucci Sunglasses
Wholesale Chanel Sunglasses
Wholesale D&G Sunglasses
Wholesale nfl jerseys
wholesale jerseys
wholesale football jerseys
authentic jerseys
Wholesale nfl jersey
wholesale nhl jerseys
wholesale hockey jerseys
discount nhl jerseys
Wholesale nba jerseys
wholesale basketball jerseys
discount nba jerseys
Wholesale mlb jerseys
wholesale baseball jerseys
discount mlb jerseys
Wholesale NCAA Jerseys
Wholesale Custom Jersey
Nike Air Max
Air Max
Nike Air Max Shoes
Air Max Shoes
Nike Air Max 2010
Air Max 95
Air Max 90
Air Max LTD
Air Max TN
Air Max Skyline
Air Max Classic



steroids shipping 01/24/2011 11:04



Nice article,awesome comments.I really enjoyed reading.keep posting.