I want to display one column (from a data source, using GridView) with html tags into a PDF . I want the HTML to be decoded so that in the PDF, it won't print the literal html tags . here's my code:
In GridView_RowDataBound event:
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
{
for (int j = 0; j < 6; j++)
{
decodeHTML = HttpUtility.HtmlDecode(GridView1.Rows[i].Cells[j].Text);
GridView1.Rows[i].Cells[j].Text = decodeHTML;
}
}
}
then added the HTML decoded gridview into PDF cell:
Phrase cellText = new Phrase(GridView1.Rows[i].Cells[j].Text, baseFontNormal);
iTextSharp.text.pdf.PdfPCell cell = new PdfPCell(cellText);
if (j == 3) cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
table.AddCell(cell);
Instead of displaying the data in a PDF format, it displays them in an HTML page (in browser). However, it will be displayed as PDF file ONLY if I remove the GridView_RowDataBound event, but then the data will print literal html tags, and I don't want this.