[英]Export grid to excel on ascx page in SharePoint 2010
我正在尝试在SharePoint Web部件解决方案的ascx页面上导出网格以使其表现出色。 它引发以下错误
Control 'ctl00_ctl24_g_20574c20_e209_4887_ab02_83ee55a79fc5_ctl00_gdReport' of type 'GridView' must be placed inside a form tag with runat=server.
为避免此错误,我必须使用以下方法,但是编译器会引发错误,指出“找不到合适的方法来覆盖”
public override void VerifyRenderingInServerForm(Control control) { }
完整代码:
protected void btnExcelExport_Click(object sender, EventArgs e)
{
PrepareForExport(gdSharedReport);
ExportToExcel();
}
private void ExportToExcel()
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=Report.xls");
Response.Charset = String.Empty;
Response.ContentType = "application/ms-excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(stringWriter);
gdSharedReport.RenderControl(HtmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
}
private void PrepareForExport(Control ctrl)
{
//iterate through all the grid controls
foreach (Control childControl in ctrl.Controls)
{
//if the control type is link button, remove it
//from the collection
if (childControl.GetType() == typeof(LinkButton))
{
ctrl.Controls.Remove(childControl);
}
//if the child control is not empty, repeat the process
// for all its controls
else if (childControl.HasControls())
{
PrepareForExport(childControl);
}
}
}
您的帖子说:
为避免此错误,我必须使用以下方法,但是编译器会引发错误,指出“找不到合适的方法来覆盖”
public override void VerifyRenderingInServerForm(Control control) { }
因此,我的猜测是您需要将替代添加到此VerifyRenderingInServerForm方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.