rhino000 says:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
PdfPTable Maintable = new PdfPTable(2);
phrase = new Phrase();
cell = new PdfPCell( new Phrase());
PdfPTable tbaleassis = new PdfPTable(2);
PdfPCell cellasss = new PdfPCell();
Phrase phra = new Phrase();
int rowindex1 = 0;
foreach (GridViewRow row1 in gvSkills.Rows)
{
TextBox t1 = (TextBox)gvSkills.Rows[rowindex1].Cells[1].FindControl( "txtskils1" );
string asa = t1.Text;
Paragraph p1 = new Paragraph(asa, FontFactory.GetFont( "Arial" , 8, Font.NORMAL));
phra.Add(p1);
rowindex1++;
}
tbaleassis.AddCell(phra);
int rowindex2 = 0;
foreach (GridViewRow row1 in gvSkills.Rows)
{
TextBox t1 = (TextBox)gvSkills.Rows[rowindex2].Cells[2].FindControl( "txtskils2" );
string asa = t1.Text;
Paragraph p1 = new Paragraph(asa, FontFactory.GetFont( "Arial" , 8, Font.NORMAL));
phra.Add(p1);
rowindex2++;
}
tbaleassis.AddCell(phra);
cellasss = new PdfPCell(tbaleassis);
table.AddCell(cellasss);
ds.Add(Maintable);
|
Why are you looping for both Colum as different foreach loop. You have used one PdfTable also then main table and then another table it’s too much confusing. Also logic behind find control its more complicated as you already written each iteration of GridviewRow you just need to find it from its item of current iteration no need to use index and no need to increment it each time as you already checking for each row in GridViewRow .
Try this Below Sample code for your reference and implement by your code logic.
It will genrate pdf containt as per grid row.
Document document = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
Font NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
Phrase phrase = null;
PdfPCell cell = null;
Color color = null;
document.Open();
phrase = new Phrase();
PdfPTable table = null;
table = new PdfPTable(2);
cell = new PdfPCell(new Phrase());
foreach (GridViewRow row1 in gvSkills.Rows)
{
PdfPCell cellasss = new PdfPCell();
cellasss.BorderWidthTop = 0;
cellasss.BorderWidthBottom = 0;
Phrase phra = new Phrase();
Phrase phra2 = new Phrase();
TextBox t1 = (TextBox)row1.FindControl("txtskils1");
TextBox t2 = (TextBox)row1.FindControl("txtskils2");
string asa = t1.Text;
string asa2 = t2.Text;
Paragraph p1 = new Paragraph(asa, FontFactory.GetFont("Arial", 8, Font.NORMAL));
Paragraph p2 = new Paragraph(asa2, FontFactory.GetFont("Arial", 8, Font.NORMAL));
phra.Add(p1);
table.AddCell(phra);
phra2.Add(p2);
table.AddCell(phra2);
}
document.Add(table);
document.Close();
byte[] bytes = memoryStream.ToArray();
memoryStream.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=Skill.pdf");
Response.ContentType = "application/pdf";
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}