【发布时间】:2014-04-28 19:05:41
【问题描述】:
我正在尝试将 gridview 导出为 excel/pdf/word 格式
我已经添加了所有必要的实现,但它仍然给我一个错误,比如“'gridview' 类型的控件必须放在带有 runat=server 的表单标签内”
请看我下面的代码,
.aspx 页面
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/OrganizationMaster.Master" EnableEventValidation="false" AutoEventWireup="true" CodeBehind="SearchInvoice.aspx.cs" Inherits="Site.pages.ContactStaff.ViewInvoice" %>
.aspx.cs 页面
public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}
.ascx.cs 控件
protected void btnExport_Click(object sender, EventArgs e)
{
if (ddlExport.SelectedIndex != 0)
{
if (ddlExport.SelectedValue == "Word")
{
Response.AddHeader("content-disposition", "attachment;filename=OtherCourses.doc");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.word";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
List<InvoiceHelper> invoicelist = svc.RetriveInvoiceList(Request.Url);
grdinvoicelist.AllowPaging = false;
grdinvoicelist.DataSource = invoicelist;
grdinvoicelist.DataBind();
grdinvoicelist.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
}
}
【问题讨论】:
-
设计页面呢?
-
你在谈论 .ascx 页面吗?
-
.aspx 因为您也使用了母版页。
标签可能有任何冲突。
标签: c# export-to-excel