TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chevy Mark Sunderland
NA
188
166.7k
Hyperlink field is empty while exporting gridview to PDF
Jun 12 2015 6:09 AM
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]
<asp:TemplateField HeaderText="link" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HyperLink ID="link" runat="server" NavigateUrl='<%# Eval("link").ToString() %>'
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">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>[/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]
Reply
Answers (
1
)
How to import the data from excel into sql database in mvc 4
IIS Configuration in windows 8.1