65.9K
CodeProject is changing. Read more.
Home

Display image in asp:HyperLinkField of GridView

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.92/5 (12 votes)

Jan 18, 2011

CPOL
viewsIcon

58650

Shows how to display an image (instead of simple text) in asp:HyperLinkField or asp:LinkButton column of a GridView

By default, asp:LinkButton and asp:HyperLinkField, being used for GridView navigation, shows simple text hyperlinks. You can easily place an image as a hyperlink. Follow this trick in order to display an image (instead of simple text) in asp:HyperLinkField or asp:LinkButton column. Here is the code for the asp:HyperLinkField to display image:
<asp:HyperLinkField Text="&lt;img src='Images/img.png' alt='alternate text' border='0'/&gt;">
</asp:HyperLinkField>
In the Text property, the less than sign (<) and the greater than sign (>) should be replaced with their Character Entities. And to show image in asp:LinkButton, use the following code:
<asp:LinkButton runat="server" Text="&lt;img src='/Images/img_btn.png' alt='Button' border='0'/&gt;">
</asp:LinkButton>