Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void btnPDF_Click(object sender, EventArgs e)
        {
            int columnsCount = GridView1.HeaderRow.Cells.Count;
            PdfPTable pdfTable = new PdfPTable(columnsCount);
            foreach (TableCell gridViewHeaderCell in GridView1.HeaderRow.Cells)
            {
                Font font = new Font();
                font.Color = new BaseColor(GridView1.HeaderStyle.ForeColor);
                PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewHeaderCell.Text, font));
                pdfCell.BackgroundColor = new BaseColor(GridView1.HeaderStyle.BackColor);
                pdfTable.AddCell(pdfCell);
            }
            foreach (GridViewRow gridViewRow in GridView1.Rows)
            {
                if (gridViewRow.RowType == DataControlRowType.DataRow)
                {
                    foreach (TableCell gridViewCell in gridViewRow.Cells)
                    {
                        Font font = new Font();
                        font.Color = new BaseColor(GridView1.RowStyle.ForeColor);
                        PdfPCell pdfCell = new PdfPCell(new Phrase(gridViewCell.Text, font));
                        pdfCell.BackgroundColor = new BaseColor(GridView1.RowStyle.BackColor);
                        pdfTable.AddCell(pdfCell);
                    }
                }
            }
            

            Document pdfDocument = new Document(PageSize.A4, 5f, 10f, 15f, 12f);
            PdfWriter.GetInstance(pdfDocument, Response.OutputStream);
            pdfDocument.Open();
            pdfDocument.Add(pdfTable);
            pdfDocument.Close();
            Response.ContentType = "application/pdf";
            Response.AppendHeader("content-disposition", "attachment;filename=Rapor.pdf");
            Response.Write(pdfDocument);
            Response.Flush();
            Response.End();
        }



This my code . Yeah it is working but it have some design problem and not for 2 grid only for one grid.

Actually ı need 2 gridview in one pdf report and it must dont have desıgn problem.

Thank for helping and sorry for my bad english.


Click For Screenshot[^]
Posted
Updated 17-Jun-14 3:03am
v2

if you need to add two pdf tables then create another one from other grid view and finally add both to the document like below
C#
pdfDocument.Add(pdfTable1);
pdfDocument.Add(pdfTable2);
 
Share this answer
 
thanks for answer well

what can ı do for design ?
 
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