I have a GridView which I export to Excel (export gridview to excel file) and it works.
But the problem is that the GridView contains a HyperLinkField
column so its gets exported to excel as a URL
while I want it to be as a text in Excel and not as a link, how do I do this?
The HyperLinkField
column, in gridview, that I have is:
<asp:HyperLinkField DataNavigateUrlFields="learntable_id" DataNavigateUrlFormatString="~/page2.aspx?learntable_id={0}" HeaderText="Learning Description" DataTextField="learntable_desc" />
I tried to fix the problem with the following:
First I gave an ID to the url column so I can be able to work with that column in codebehind so I replace the Hyperlinkfield with a Hyperlink like this:
<asp:TemplateField HeaderText="Learning Description"> <ItemTemplate> <asp:HyperLink id="hyperlinkcolumn" runat="server" NavigateUrl='<%# "~/page2.aspx?learntable_id=" & Eval("learntable_id") %>' text='<%# Eval("learntable_desc") %>' ></asp:HyperLink> </ItemTemplate> </asp:TemplateField>
and in the Export to Excel code in page behind I try to
convert
that column to a text but I fail and I am not sure if I do it right:For Each gr As GridViewRow In GridView1.Rows Convert.ToString(CType(gr.Cells(1).FindControl("hyperlinkcolumn").ToString, String)) Next
But I can't arrive to change the link column to a text column, help please.