Click here to Skip to main content
15,898,653 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a gridview which is bound dynamically from database...
I want to export it to an excel sheet...
Gridview has paging and sorting enabled...
Edit and Delete buttons are also allowed...
Please any help would be appreciated...
Posted
Comments
Sandeep Mewara 6-Feb-13 2:17am    
And what have you tried so far?
Sriram Bala 6-Feb-13 2:25am    
Do you need to export only data present in current page or the whole content, since you mentioned paging.
Member 9644631 6-Feb-13 2:36am    
Both ways..
Depending upon the the users choice....

create this code in cs file and your problem are solw

public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
protected void btn_excel_report_Click(object sender, EventArgs e)
{
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=Late_Coming.xls");
Response.ContentType = "application/excel";
StringWriter sWriter = new StringWriter();
HtmlTextWriter hTextWriter = new HtmlTextWriter(sWriter);

grd_bonus.RenderControl(hTextWriter);
Response.Write(sWriter.ToString());
Response.End();
}
 
Share this answer
 
use below link which is help you sure.


Click on this
[^]


Happy Coding.
 
Share this answer
 
Try this link, has pretty much the same thing that you want
Gridview to Excel export[^]
 
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