0
一直試圖將放置在ContentPlaceHolder中的gridview的內容導出到Excel。 顯然,.aspx頁面中沒有包含表單標籤。它在主頁面中。將GridView導出到Excel需要將GridView放置在窗體標記中
此行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,但相同的!