troubleshooting Question

create table

Avatar of 1jaws
1jawsFlag for United States of America asked on
C#.NET ProgrammingASP.NET
5 Comments2 Solutions313 ViewsLast Modified:
How to create to table using iTextSharp and fill fields using data from stored proc. I cant see the table..
I used this http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables

Thanks..
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);       

        doc.Open();
        PdfPTable table = new PdfPTable(3);

        PdfPCell cell = new PdfPCell(new Phrase("Header spanning 3 columns"));

        cell.Colspan = 3;

        cell.HorizontalAlignment = 1;  
        table.AddCell(cell);

        table.AddCell("Col 1 Row 1");

        table.AddCell("Col 2 Row 1");

        table.AddCell("Col 3 Row 1");

        table.AddCell("Col 1 Row 2");

        table.AddCell("Col 2 Row 2");

        table.AddCell("Col 3 Row 2");

        doc.Add(table);

        
        table.TotalWidth = 216f;

        
        table.LockedWidth = true;



        
        float[] widths = new float[] { 1f, 2f };

        

        table.HorizontalAlignment = 0;

       

        table.SpacingBefore = 20f;

        table.SpacingAfter = 30f;

        cell.Colspan = 2;

        cell.Border = 0;

        cell.HorizontalAlignment = 1;

        table.AddCell(cell);

        
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["xxx"].ConnectionString);
        SqlDataReader reader = null;

       
            try
            {
            conn.Open();

            SqlCommand comm = new SqlCommand("selectPDF conn);
            comm.CommandType = CommandType.StoredProcedure;

           
            comm.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int));
            comm.Parameters["@ID"].Value = Convert.ToInt32(lblID.Text);

            reader = comm.ExecuteReader();

            while (reader.Read())
            {
                table.AddCell(reader[0].ToString());

                table.AddCell(reader[1].ToString());

            }

            }

            catch (Exception ex)
            {

                Response.Write(ex.Message);

            }

            doc.Add(table);
            doc.Close();
        }
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros