Click here to Skip to main content
15,908,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anybody help me to solve this article
" Export datagrid view to Word in C# " .can you help me by giving the code or related links in C#
Posted
Updated 28-Nov-10 22:49pm
v2

1 solution

try this,
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=filename.doc");
Response.Charset = "";
Response.ContentType = "application/msword";

StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

grid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

If u run this code now, you will get error - 'Control 'ctl00_ContentPlaceHolder1_grid' of type 'GridView' must be placed 'inside a form tag with runat=server'. so, Don't worry. Just copy and paste the below code. Its done.
public override void VerifyRenderingInServerForm(Control control)
{
    // Confirms that an HtmlForm control is rendered for the specified ASP.NET
    // server control at run time. <br>
}</br>
 
Share this answer
 
v4
Comments
sevenbell 29-Nov-10 4:51am    
thanks for your replay and your code But i need C# code i don't know to convert this code to C# .so please help me.
Toniyo Jackson 29-Nov-10 4:54am    
Check now. i changed to c#.
sevenbell 29-Nov-10 4:58am    
No sir It not updated i didn't get the code
Toniyo Jackson 29-Nov-10 5:02am    
check this 'http://www.codeproject.com/Questions/131805/datagridview-to-worddocument.aspx'

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