0
我想導出幾個pdf格式的gridviews,他們不是在HtmlTextWriter呈現 Gridviews是動態創建,嵌套在中繼器控制。 作爲數據源,我使用的是數據表,儘管表格在瀏覽器中顯示(連同它們的數據),但它們不會以pdf文件格式顯示。中繼器中嵌套的gridview沒有導出在PDF
代碼以下 謝謝!
ASPX:
<asp:Panel ID="pnlContent" runat="server">
<asp:Repeater ID="rptResult" runat="server" OnItemDataBound="rptResult_ItemDataBound" EnableViewState="false">
<HeaderTemplate>
Detalii test<br />
</HeaderTemplate>
<ItemTemplate>
<asp:Literal ID="ltGroupId12" runat="server" Visible="false" Text='<%# Eval("GroupId12")%>'></asp:Literal>
<asp:GridView ID="gvResultDetail" runat="server" AutoGenerateColumns="false" ShowHeader="false" GridLines="Both"
OnRowDataBound="gvResultDetail_RowDataBound">
<Columns>
<asp:BoundField DataField="Group1Desc" ItemStyle-CssClass="gridviewItemGroup1TestResult" />
<asp:BoundField DataField="Group2Desc" ItemStyle-CssClass="gridviewItemGroup2TestResult"/>
<asp:TemplateField ItemStyle-CssClass="gridviewItemStdTestResult">
<ItemTemplate>
test
<asp:Label ID="lblRequestedResultText" runat="server" Visible="false" Text="Position request<br />Total: "></asp:Label>
<asp:Label ID="lblRequestedResultValue" runat="server" Visible="false" Text='<%# Eval("RequestedResult")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="gridviewItemStdTestResult">
<ItemTemplate>
<asp:Label ID="lblActualResultText" runat="server" Visible="false" Text="Answer level<br />Total: "></asp:Label>
<asp:Label ID="lblActualResultValue" runat="server" Visible="false" Text='<%# Eval("ActualResult")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="gridviewItemStdTestResult">
<ItemTemplate>
<asp:Label ID="lblDifferencesText" runat="server" Visible="false" Text="Difference:"></asp:Label>
<asp:Label ID="lblDifferencesValue" runat="server" Visible="false" Text='<%# Eval("Differences")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="gridviewItemStdTestResult">
<ItemTemplate>
<asp:Label ID="lblPercentageText" runat="server" Visible="false" Text="KQ<br />"></asp:Label>
<asp:Label ID="lblPercentageValue" runat="server" Visible="false" Text='<%# Eval("Percentage") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="false">
<ItemTemplate>
<asp:Literal ID="ltGroupType" runat="server" Visible="false" Text='<%# Eval("RecordType")%>'></asp:Literal>
<asp:Literal ID="ltNoRows" runat="server" Visible="false" Text='<%# Eval("NoRows")%>'></asp:Literal>
<asp:Literal ID="ltBasicDomain" runat="server" Visible="false" Text='<%# Eval("BasicDomain")%>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="gridviewHeaderTestResult" />
<RowStyle CssClass="gridviewRowTestResult" />
<AlternatingRowStyle CssClass="gridviewRowTestResult" />
</asp:GridView>
</ItemTemplate>
<SeparatorTemplate>
<br />
</SeparatorTemplate>
<FooterTemplate>
End
</FooterTemplate>
</asp:Repeater>
<br />
</asp:Panel>
ASPX.CS:
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=SDT.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
DataTable dtDetailedResult = (DataTable)Session["dtDetailedResult"];
rptResult.DataSource = dtDetailedResult;
rptResult.DataBind();
pnlContent.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 70f, 70f, 20f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
這就是我正在使用的itextsharp.dll - 但只有已定義的aspx表/ gridviews被htmltextwriter「顯示」並顯示在pdf文件中,那些通過使用中繼器項目中的嵌套控件動態生成的代碼不會被呈現.... –
我已經寫完了用數據源代碼嵌入我的數據的html標籤 - 如果你有其他解決方案,請告訴我,像這樣:hw.Write(「
相關問題