I do have a form tag setup runat=server. But it continue to fail.
Solution: Create an HtmlForm object and add the grid view to the form in code.
string style = @" ";
Response.ClearContent();
// Create form tag
HtmlForm form1 = new HtmlForm();
form1.Controls.Add(gvData);
Response.AddHeader("content-disposition", "myfilename.xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
StringWriter header= new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvData.RenderControl(htw);
// Style is added dynamically
Response.Write(style);
Response.Write(sw.ToString());
Response.End();
No comments:
Post a Comment