Click here to Skip to main content
15,888,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want To export data from gridview to word.

This Is my Code:-
C#
Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition","attachment;filename=GridViewExport.doc");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-word ";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();


But It show ing error and error is that:-
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.

How Can I solve this problem.

Please Help Me.

Thanks.
Posted
Updated 29-Nov-11 23:34pm
v2
Comments
Prince Antony G 30-Nov-11 6:20am    
check ur gridview control in design page.

1 solution

check your gridview inside
C#
<form runat="Server">
.
.
//gridview code
.
.
</form>
 
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