如何在DotNetNuke(DNN)中导出Pdf中的Gridview数据?

时间:2013-02-15 06:33:03

标签: dotnetnuke

如何在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

的表单标记内

我也尝试使用这种方法尽可能多地给出解决方案,即渲染gridview的问题  public override void VerifyRenderingInServerForm(Control control)        {           //base.VerifyRenderingInServerForm(control);        }

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

请提供合适的解决方案

2 个答案:

答案 0 :(得分:0)

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

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

That's Too Easy - Implementing DNNGrid (aka Telerik RadGrid)

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

Telerik RadGrid - Export to PDF

答案 1 :(得分: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();     
}