尝试将放置在ContentPlaceHolder中的gridview的内容导出到Excel。 显然,.aspx页面中不包含任何表单标记。它在主页面中。
这一行gvRapor.RenderControl(hwr);
给出错误:
Control 'cphIcerik_gvRapor' of type 'GridView' must be placed inside a form tag with runat=server.
代码:
StringWriter swr = new StringWriter();
HtmlTextWriter hwr = new HtmlTextWriter(swr);
for (int j = 0; j < gvRapor.Rows.Count; j++)
{
GridViewRow row = gvRapor.Rows[j];
gvRapor.RenderControl(hwr);
Context.Response.Write(swr.ToString());
Context.Response.Flush();
Context.Response.End();
}
尝试了几乎所有可能的Response.ContentType值,但是相同!
答案 0 :(得分:1)
我认为你在呼叫gvRapor.RenderControl(hwr);
,我想你不会超载VerifyRenderingInServerForm
尝试在文件中添加以下代码
public override void VerifyRenderingInServerForm(Control control)
{
/* HtmlForm control is rendered at run time. */
}
看看这个VerifyRenderingInServerForm
我希望这有帮助!