Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i use following code in aspx.cs page to export to excel
its work fine
C#
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename=g.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter ht = new HtmlTextWriter(sw);
gvDisplay.AllowPaging = false;
gvDisplay.DataBind();
gvDisplay.RenderControl(ht);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();

C#
Collapse | Copy Code
public override void VerifyRenderingInServerForm(Control control)
{

}

but i want to create global functon in my common class i try followin
C#
public void export(GridView gvDisplay, fileName)
{
     Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition","attachment;filename="+fileName+".xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter ht = new HtmlTextWriter(sw);
gvDisplay.AllowPaging = false;
gvDisplay.DataBind();
gvDisplay.RenderControl(ht);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}

but i cant use
C#
public override void VerifyRenderingInServerForm(Control control)
{

}

method in class
pls help me to solve it
Thank u
Posted
Updated 16-Feb-12 1:53am
v2

 
Share this answer
 
Hi, use below link. it will provide a best solution and a well formatted excel.

Export to Excel from GridView in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900