ASP.NET の Excel シートへのデータ転送グリッド ビュー。この種の問題を解決する方法 エラーは
Control 'ContentPlaceHolder1_gvdetails' of type 'GridView' must be placed inside a form tag with runat=server.
これは私のコードです:
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}",
"Customers.xls"));
Response.ContentType = "application/ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false; gvdetails.DataBind();
gvdetails.HeaderRow.Style.Add("background-color", "#FFFFFF");
gvdetails.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();