1

如何在 DotNetNuke(DNN) 中以 Pdf 格式导出 Gridview 数据?

代码背后的代码是: -

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=PurchaseOrderDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView gridview1 = new GridView();

gridview1.AllowPaging = false;
//DataSet ds = objOrderRegistratonController.GetOrders();                
grddisplay.DataBind();
grddisplay.RenderControl(hw);
grddisplay.HeaderRow.Style.Add("width", "15%");
grddisplay.HeaderRow.Style.Add("font-size", "10px");
grddisplay.Style.Add("text-decoration", "none");
grddisplay.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
grddisplay.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

错误来了:- 'gridview' 类型的控件必须放在带有 runat=server 的表单标签内

我也尝试使用这种方法,因为许多人给出了解决方案,它的网格视图渲染问题 public override void VerifyRenderingInServerForm(Control control) { //base.VerifyRenderingInServerForm(control); }

但是这种方法在 DNN 'MPPR.mpprcms_OrderRegistraton.ViewPurchaseOrder.VerifyRenderingInServerForm(System.Web.UI.Control)' 中给出错误:找不到合适的方法来覆盖

请给出合适的解决方案

4

2 回答 2

0
public override void VerifyRenderingInServerForm(Control control)

{
    /* Verifies that the control is rendered */ 
}

protected void GeneratePDF_Click(object sender, EventArgs e) {

    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.AllowPaging = false;
    GridView1.DataBind();
    GridView1.RenderControl(hw);
    GridView1.HeaderRow.Style.Add("width", "15%");
    GridView1.HeaderRow.Style.Add("font-size", "10px");
    GridView1.Style.Add("text-decoration", "none");
    GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
    GridView1.Style.Add("font-size", "8px");
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();     
}
于 2015-04-21T08:10:16.503 回答
0

您是否尝试过将 DotNetNuke 包装器控件用于支持导出为各种格式的 Telerik 网格。我不使用包装器,但它可能会帮助您实现您想要实现的目标。

关于如何使用包装器的链接

这太容易了——实现 DNNGrid(又名 Telerik RadGrid)

有关用于导出的 telerik radgrid 控件的链接。

Telerik RadGrid - 导出为 PDF

于 2013-03-15T05:40:08.487 回答