Link to home
Start Free TrialLog in
Avatar of Srinivas Mantha
Srinivas ManthaFlag for India

asked on

ASP.NET 3.5: Problem exporting grid contents to word from a child page: ErrorCode=-2147467259

I am using ASP.NET 3.5 with C# code.  I have gridview by name “gridinfo” in a child page populated by records from a database.  I am using a standard function to export the grid contents to word.
private void exportgridinfotoword()

    {
       
        Response.Clear();
  Response.AddHeader("content-disposition", "inline;filename=abc.doc");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.word";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
       
        gridinfo.RenderControl(htw);
        Response.Write(sw.ToString());

        Response.Flush();
        Response.End();
    }
}

I am getting the following error
Message="Control 'ctl00_Main_gridinfo' of type 'GridView' must be placed inside a form tag with runat=server." Source="System.Web"
What is the problem and likely solution
ASKER CERTIFIED SOLUTION
Avatar of Rahul Agarwal
Rahul Agarwal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

The error message looks like you are mssing runat="server2 on your form tag ot <form sunat="server"> itself is missing

-- Deepu