如何在ASP.NET中将AJAX Accordion数据转换为PDF
大家好,
我在ASP.NET 3.5中创建的应用程序中有手风琴。
我想转换活动手风琴数据按pdf点击按钮。
例如手风琴中有04个窗格。用户单击第二个窗格然后单击按钮,Accortion Pane Index#01的数据应转换为PDF。
Inshort如何从Accordion获取该数据。
数据正在DataTable中填充,然后填充到Accordion Pane内的HTML表格。
以下是代码:
Hi All,
I have an accordion in my application created in ASP.NET 3.5.
I want to convert the active accordion data to pdf on button click.
For Example there are 04 panes in that accordion. And the user clicks the 2nd pane and then click on button, the data of Accortion Pane Index#01 should be converted to PDF.
Inshort how can I get that data from Accordion.
Data is being populated in DataTable and then to HTML table inside Accordion Pane.
Here is the code:
protected void Page_Load(object sender, EventArgs e)
{
AccordionPane pane = new AccordionPane();
pane.HeaderContainer.Controls.Add(new LiteralControl("From " + fr.ToString("dd-MMM-yyyy") + " To " + to.ToString("dd-MMM-yyyy")));
pane.ContentContainer.Controls.Add(new LiteralControl(gen_table(loc, dept, fr.ToString("dd-MMM-yyyy"), to.ToString("dd-MMM-yyyy"))));
//gen_table(....) is a method in which HTML table is created.
MyAccordion.Controls.Add(pane);
MyAccordion.SelectedIndex = i;
fr = to.AddDays(1);
GeneratePDF(pane.ToString()); // This doesn't work. :(
}
public void GeneratePDF(string pane)
{
Document doc = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10);
PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath + "\\" + Session["ecd"] + " - Attendance_Sheet.pdf", FileMode.Create));
HeaderFooter footer = new HeaderFooter(new Phrase("Page: ", FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL)), true);
footer.Border = Rectangle.TOP_BORDER;
doc.Footer = footer;
doc.Open();
Paragraph ho = new Paragraph("ORIX LEASING PAKISTAN LIMITED", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.UNDERLINE));
ho.SetAlignment("CENTER");
doc.Add(ho);
Paragraph ha = new Paragraph("Attendance Sheet", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.UNDERLINE));
ha.SetAlignment("CENTER");
doc.Add(ha);
Paragraph myParagraph = new Paragraph(Lbl_Frm.Text +" TO "+ Lbl_To.Text, FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.UNDERLINE));
myParagraph.SetAlignment("CENTER");
doc.Add(myParagraph);
Paragraph locp = new Paragraph("KARACHI - INFORMATION SYSTEMS", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.UNDERLINE));
myParagraph.SetAlignment("CENTER"); // ????
doc.Add(locp);
iTextSharp.text.Table tableh = new iTextSharp.text.Table(11);
tableh.Width = 100;
//tableh.SetWidths(new int[2] { 5, 25 });
tableh.Border = 0;
tableh.Cellpadding = 1;
Paragraph srr = new Paragraph(pane, FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.NORMAL));
Cell csrr = new Cell(srr);
csrr.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
csrr.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
csrr.Header = true;
tableh.AddCell(csrr);
tableh.EndHeaders();
doc.Add(tableh);
doc.Close();
}
请帮助。
谢谢,
AR。
Please Help.
Thanks,
AR.
试试这样的事情
Try something like this
foreach (AccordionPane Pane in AccordionID.Panes)
{
Literal lit = (Literal)Pane.ContentContainer.FindControl("LiteralID");
if (lit != null)
var value =lit.Text;// change to a stringbuilder and then append the values of each literal in the Accordion pane
}
希望这有助于......
Hope this helps...