user5468794 user5468794 - 1 year ago 113
ASP.NET (C#) Question

asp:hyperlinkfield showing path rather than datatextfield

I have a grid view that populates two columns. One with the name of a file and the other with a path that links to a pdf.

<asp:GridView ID="Grid" runat="server" AutoGenerateColumns="false" Font-Names="Arial"
Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green"
AllowPaging="false" PageSize="10" OnRowDataBound="Grid_RowDataBound">
<asp:BoundField ItemStyle-Width="80%" DataField="Name" HeaderText="Name"></asp:BoundField>
<asp:hyperlinkfield headertext="PDF" datatextfield="PDF" datanavigateurlfields="PDF" datanavigateurlformatstring="" text="PDF" />

I have tried renaming the field to say "PDF" rather than displaying that documents path. How can I have it be show "PDF" on the webpage rather than displaying the document path to the user?

Answer Source

Remove the DataTextField attribute and it will use the Text attribute as link text.

<asp:HyperLinkField HeaderText="PDF" DataNavigateUrlFields="PDF" Text="Download PDF" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download