2013-02-15 52 views
1

如何在DotNetNuke(DNN)中的PDF中導出Gridview數據?如何使用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 =服務器

我也嘗試使用這種方法很多給出的解決方案,它的渲染GridView的問題 public override void VerifyRenderingInServerForm(Control control) //base.VerifyRenderingInServerForm(control); }

但這種方法給出錯誤在DNN 'MPPR.mpprcms_OrderRegistraton.ViewPurchaseOrder.VerifyRenderingInServerForm(System.Web.UI.Control)':發現重寫

請給合適的溶液中沒有合適的方法

回答

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();  
} 
相關問題