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
9
Recent comments