Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends. i have requirement on gridview to excel in asp.net . here i wrote code in export button in the following code.

C#
Response.Clear();
Response.Buffer = true;
string filename = "GridViewExport_" + DateTime.Now.ToString() + ".xls";

Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.Charset = "";
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvwReport.RenderControl(hw);

Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();



if we want to save the file, empty data is coming.

how can do the this task to exporting in excel with header color.

please help me anyone.

advanced thanks.
Posted
Updated 24-Jul-13 1:41am
v2
Comments
[no name] 24-Jul-13 7:35am    
Well near as I can tell, you are not actually writing anything....

Use SearchBox[^] on the top-right corner of this site. There you'll find thousands of similar questions with answers.
 
Share this answer
 
Comments
_Amy 24-Jul-13 8:44am    
Exactly. +5!
Maciej Los 24-Jul-13 8:48am    
Thank you, Amit ;)
i have done the same thing and posted in my blog.
just check here http://kishsharmasoftcode.blogspot.in/[^]
for any query comment on that.
Hope help you.
Thanks,
 
Share this answer
 
v2

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