Hi guys,
i was trying to export repeater data to pdf in asp.net using c#,
where in a repeater i have web user controls also.
to export this, i'm using itextshare.dll
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Text;
protected void btnExport_Click(object sender, ImageClickEventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
DailyReportRepeater.DataBind();
DailyReportRepeater.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
trying:
i have already bind the repeater in the pageload, if(!ispostback).
....
in btnexport code:
i have commented
n then checked the repeater count n it was greater than zero
int c = DailyReportRepeater.Items.Count;
,
but if i uncommented this line ' DailyReportRepeater.DataBind();'
then the count is getting zero.
the problem is in binding of a repeater.
can anyone please help me to solve this issue.
Thanks