Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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();
    }


Please Help.


Thanks,
AR.
Posted
Updated 8-Dec-13 20:31pm
v2
Comments
JoCodes 6-Dec-13 4:24am    
Are you using Controls to hold data in the Accordion?
AR547 6-Dec-13 5:05am    
No..its HTML Table only in which Data is populated. and this table is created dynamically in code behind.
JoCodes 7-Dec-13 1:56am    
Any code you have tried so far? if so post the code to the question
AR547 8-Dec-13 23:30pm    
Yeah I have but its just a simple html table created dynamically in code behind in which that data table data is being populated and that html table is in accordion.
Thanks.
JoCodes 8-Dec-13 23:57pm    
Can post the code you tried so that it will be easy for CP members to help you

1 solution

Try something like this

C#
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...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900