I work in ASP.NET 4 C#.
I have a GridView, that one of it's columns is HyperLink (the others are regular BoundField).
Now I need export this GridView in pdf and I have worked with iTextSharp library http://technico.qnownow.com/export-gridview-data-pdf-using-itextsharp/
They look like that:
[code]
ImageUrl='<%#(String.IsNullOrEmpty(Eval("link").ToString()) ? "/Images/cross-button.png" : "/Images/download.gif")%>'
ToolTip='<%#(String.IsNullOrEmpty(Eval("link").ToString()) ? "empty link" : "go to link")%>'
Target="_blank" BorderStyle="None" ForeColor="Transparent">
[/code]
In the code-behind I only use databind, and then export to pdf.
Everything works perfectly except this one column that is empty.
I have tried to replace:
[code]
cellText = Server.HtmlDecode(gvProducts.Rows[rowIndex].Cells[j].Text);[/code]
with
[code]
cellText = Server.HtmlDecode((gvProducts.Rows[rowIndex].Cells[j].FindControl("link") as HyperLink).NavigateUrl);[/code]
But in output pdf in all columns I have the value of HyperLink.
Can you please help me figure out the problem?
Thanks in advance.
My code below.
[code]
//export rows from GridView to table
for (int rowIndex = 0; rowIndex < gvProducts.Rows.Count; rowIndex++)
{
if (gvProducts.Rows[rowIndex].RowType == DataControlRowType.DataRow)
{
for (int j = 0; j < gvProducts.Columns.Count - 1; j++)
{
//fetch the column value of the current row
//cellText = Server.HtmlDecode(gvProducts.Rows[rowIndex].Cells[j].Text);
cellText = Server.HtmlDecode((gvProducts.Rows[rowIndex].Cells[j].FindControl("link") as HyperLink).NavigateUrl);
//create a new cell with column value
//cell = new PdfPCell(new Phrase(cellText));
cell = new PdfPCell(new Phrase(cellText, FontFactory.GetFont("nina fett", 8)));
//Set Color of Alternating row
if (rowIndex % 2 != 0)
{
cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#9ab2ca"));
}
else
{
cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#f1f5f6"));
}
//add the cell to the table
table.AddCell(cell);
}
}
}[/code]
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted Jun 14, 2015, 2:13 AM
cellText = Server.HtmlDecode(gvProducts.Rows[rowIndex].Cells[j].Text);
}
else{
cellText = Server.HtmlDecode((gvProducts.Rows[rowIndex].Cells[j].FindControl("link") as HyperLink).NavigateUrl);
}