I write a web program with ASP and C#. In default.aspx.cs i have a ListView with data: Name - DOB - Address - etc. How can i export this
ListView to PDF file?
I did with itexthelp, but when i click the button "Export to PDF", then display a fault: ListView.RenderControl(hw); <-- The control ListView1_lbNname type LinkButton must be positioned in a form tag with runat = server.
After run main.aspx from local, i become another fault:
Description: Error during compilation of a resource that is required to process this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'iTextSharp' could not be found. (Missing a using directive or an assembly reference?)
Source Error:
Line 8: using System.Web.UI;
Line 9: using System.Web.UI.WebControls;
Line 10: using iTextSharp.text; <------------------------
Line 11: using iTextSharp.text.pdf;
Line 12: using iTextSharp.text.html;
ChristianDin...
Member
1 Points
8 Posts
How to export a ListView to PDF (C# Code behind ASPX)
Feb 26, 2013 08:23 PM|LINK
Hello everybody,
I write a web program with ASP and C#. In default.aspx.cs i have a ListView with data: Name - DOB - Address - etc. How can i export this ListView to PDF file?
Every help would be appreciated. Thank
funluckykitt...
Participant
1469 Points
1547 Posts
Re: How to export a ListView to PDF (C# Code behind ASPX)
Feb 26, 2013 08:28 PM|LINK
Anything to do with exporting to .pdf, I do with iTextSharp. Here's the link... http://itextpdf.com/
ChristianDin...
Member
1 Points
8 Posts
Re: How to export a ListView to PDF (C# Code behind ASPX)
Feb 26, 2013 08:39 PM|LINK
I did with itexthelp, but when i click the button "Export to PDF", then display a fault: ListView.RenderControl(hw); <-- The control ListView1_lbNname type LinkButton must be positioned in a form tag with runat = server.
And here is aspx code:
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="ID"
OnSorting="ListView1_Sorting" OnSelectedIndexChanging="ListView1_SelectedIndexChanging">
<LayoutTemplate>
<table id="Table1" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr id="Tr2" runat="server" style="">
<th id="Th12" runat="server"></th>
<th id="Th1" runat="server" style="width: 60px">ID</th>
<th id="Th2" runat="server" style="text-align: center; width: 80px; color: #3333FF; font: bold">
<asp:LinkButton ID="lbNname" runat="server" CommandArgument="Firstname" CommandName="Sort" Text="Firstname" ForeColor="Blue"/>
</th>
<th id="Th3" runat="server" style="text-align: center; width: 90px; color: #3333FF; font: bold">
<asp:LinkButton ID="lbVname" runat="server" CommandArgument="Lastname" CommandName="Sort" Text="Lastname" ForeColor="Blue" />
</th>
.........
What should I do now ?
ChristianDin...
Member
1 Points
8 Posts
Re: How to export a ListView to PDF (C# Code behind ASPX)
Feb 26, 2013 08:45 PM|LINK
After run main.aspx from local, i become another fault:
Description: Error during compilation of a resource that is required to process this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'iTextSharp' could not be found. (Missing a using directive or an assembly reference?)
Source Error:
Line 8: using System.Web.UI;
Line 9: using System.Web.UI.WebControls;
Line 10: using iTextSharp.text; <------------------------
Line 11: using iTextSharp.text.pdf;
Line 12: using iTextSharp.text.html;
Sharon59
Member
180 Points
31 Posts
Re: How to export a ListView to PDF (C# Code behind ASPX)
Feb 27, 2013 04:53 AM|LINK
oleDbConnection1.Open(); this.cellExport1.ActionAfterExport = DataExport.Common.ActionType.None; this.cellExport1.DataSource = DataExport.Common.ExportSource.ListView; this.cellExport1.ListView = this.listView1; Using(MemoryStream stream = new MemoryStream()) { cellExport1.SaveToFile(stream); this.oleDbConnection1.Close(); Workbook workbook = new Workbook(stream); PdfConverter pdfConverter = new PdfConverter(workbook); PdfDocument pdfDocument = new PdfDocument(); pdfDocument.PageSettings.Orientation = pdf.PdfPageOrientation.Landscape; pdfDocument.PageSettings.Width = 970; pdfDocument.PageSettings.Height = 850; PdfConverterSettings settings = new PdfConverterSettings(); settings.TemplateDocument = pdfDocument; pdfDocument = pdfConverter.Convert(settings); pdfDocument.SaveToFile("test.pdf"); }I use a ExportData Library introduced here: http://exportdata.codeplex.com/