Click here to Skip to main content
15,904,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to generate pdf using Itextsharp , but i am unable to get repeater value inside Itextsharp


What I have tried:

sb.Append("");
String imageURL = @"*****";
String imageURL1 = @"******";
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("<table width="100%" cellspacing="0" cellpadding="2"><tbody><tr><td colspan="4"></td></tr><tr><td></td><td></td><td></td> <td></td></tr><tr><td style="font-size: 10px" colspan="4">TSW Packaging Solutions</td></tr><tr><td style="font-size: 10px" colspan="4">S No 8, Sagun Niwas Dange Chowk – Tathawade Road, Tathawade, Pune - 411033</td> </tr><tr><td style="font-size: 10px" colspan="2"> REF :- " + lblticket.Text + " </td> <td style="font-size: 10px" colspan="2">Date :-  " + System.DateTime.Today + "</td> </tr><tr><td style="font-size: 10px" colspan="4"> Kind Attn :- " + lblcustomer.Text + " </td>  </tr><tr><td style="font-size: 10px" colspan="4"> M/S. :- " + lblcompany.Text + " </td>  </tr><tr><td style="font-size: 10px" colspan="4"> Subject :- " + txtsubject.Text + " </td>  </tr><tr><td style="font-size: 10px" colspan="4">  " + txtbody.Text + " </td>  </tr><tr><td style="font-size: 10px" colspan="4">  " productbind(); " </td>  </tr></tbody></table>");
Posted
Updated 28-Mar-18 23:51pm
Comments
Christiaan van Bergen 29-Mar-18 4:59am    
You mean you want to iterate over some data rows to create a table in your PDF?
Could you expand your question with a sample/mockup of the desired output?
ADI@345 29-Mar-18 5:17am    
yes i have to iterate row but coming from database..
ADI@345 29-Mar-18 5:04am    
for example i have table that is coming from database inside repeater for this i made a function and call, but at the time of creating pdf, i am unable to call function to create table ..
here productbind(); is a function ..

Hi,

I think you can construct something with an iteration over the table rows while building your string. Something in the order of:

(warning pseudo code)
C#
...
sb.Append("");
// Just construct your layout, e.g. table and styling

// And continue to iterate over your data
foreach(var row in YourCollectionOfRows){
  // include any styling if you like 
  sb.Append($"Customer name: {row.CustomerName}");
  sb.Append($"Ticket number: {row.TicketNumber}");
}

// And finalize the layout (closing the table structure and stuff)
sb.Append("");
...


HtH Christiaan
 
Share this answer
 
v2
For one thing, that's completely unreadable. For another, you either have to use single quotes around the various html attribute values or escape the double quotes.

C#
sb.AppendLine  ("<table width='100%' cellspacing='0' cellpadding='2'>");
sb.AppendLine  ("    <tbody>");
sb.AppendLine  ("        <tr>");
sb.AppendLine  ("            <td colspan='4'></td>");
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("        <tr><td></td><td></td><td></td> <td></td></tr>");
sb.AppendLine  ("        <tr><td style='font-size:10px;' colspan='4'>TSW Packaging Solutions</td></tr>");
sb.AppendLine  ("        <tr><td style='font-size:10px;' colspan='4'>S No 8, Sagun Niwas Dange Chowk – Tathawade Road, Tathawade, Pune - 411033</td></tr>");
sb.AppendLine  ("        <tr>");
sb.AppendFormat("            <td style='font-size:10px;' colspan='2'> REF :- {0}</td>", lblticket.Text);.AppendLine();
sb.AppendFormat("            <td style='font-size:10px;' colspan='2'>Date :-  {0}</td>", System.DateTime.Today);.AppendLine();
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("        <tr>");
sb.AppendFormat("            <td style='font-size:10px;' colspan='4'> Kind Attn :- {0}</td>", lblcustomer.Text);.AppendLine();
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("        <tr>");
sb.AppendFormat("            <td style='font-size:10px;' colspan='4'> M/S. :- {0}</td>", lblcompany.Text).AppendLine();
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("        <tr>");
sb.AppendFormat("            <td style='font-size:10px;' colspan='4'> Subject :- {0}</td>", txtsubject.Text).AppendLine(); 
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("        <tr>");
sb.AppendFormat("            <td style='font-size:10px;' colspan='4'>  {0}</td>", txtbody.Text).AppendLine();  
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("        <tr>");
//SEE EDIT BELOW
//sb.AppendFormat("            <td style='font-size:10px;' colspan='4'>  {0}</td>", productbind()).AppendLine();
sb.AppendLine  ("        </tr>");
sb.AppendLine  ("    </tbody>");
sb.AppendLine  ("</table>");



I don't know what the productbind method does.

EDIT ===============================

Your responses are STILL too vague for precise help, but this should be what you're looking for. I can't possibly spoon feed you more than this because you're piece-mealing the info to us and frankly, I'm bored with the question. Be a programmer and nut it out from here.
C#
var product = productbind();
sb.AppendFormat("      <td style='font-size:10px;'>{0}</td>", product.field1).AppendLine();
sb.AppendFormat("      <td style='font-size:10px;'>{0}</td>", product.field2).AppendLine();
sb.AppendFormat("      <td style='font-size:10px;'>{0}</td>", product.field3).AppendLine();
sb.AppendFormat("      <td style='font-size:10px;'>{0}</td>", product.field4).AppendLine();
 
Share this answer
 
v4
Comments
ADI@345 29-Mar-18 5:55am    
productbind is a function
#realJSOP 29-Mar-18 5:57am    
I know - I just don't know what it does, so I can't comment on what you're going to see.
ADI@345 29-Mar-18 6:00am    
i use repeater to fetch table from database inside productbind() function.. and call productbind() to get record.
#realJSOP 29-Mar-18 7:38am    
I edited my answer - again.
ADI@345 29-Mar-18 7:44am    
sir, i did this work .. thanks for your help..

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