Thursday 18 february 2010 4 18 /02 /Feb /2010 13:05
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();

        }
By Balavardhan Reddy - Posted in: ASP.Net
Write comment - See the 9 comments
Home

My Blog

Profile

  • Balavardhan Reddy
  • Balavardhan Reddy Narani
  • Male
  • Life ASP.Net SQL Server Good Quotes SSRS
  • Software Eng.. From India..

Categories

Random pictures

  • 4.jpg
  • 3.gif
  • 2.jpg
  • 2.gif
  • 5.jpg

Recent comments

Recommend

Links

Create your blog for free on over-blog.com - Contact - Terms of Service - Earn Royalties - Report abuse - Most commented articles