在 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();