Click here to Skip to main content
Click here to Skip to main content

Display image in asp:HyperLinkField of GridView

By , 19 Jan 2011
 
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>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Awais Hafeez 86
Pakistan Pakistan
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionExcelentmembernecoide4 Apr '13 - 9:00 
Thanks. I can't add a templatefield in my gridview because it is using EnableSortingAndPagingCallbacks. This solution helped me a lot. Big Grin | :-D
GeneralMy vote of 5memberMember 977903924 Feb '13 - 23:12 
Tricky
QuestionGreat Tip!memberAlman6611 Oct '12 - 2:26 
Nothing more to say. I sometimes can be sooo easy... You just need to know Wink | ;-) Cool | :cool:
GeneralReason for my vote of 3 Why do someone use this complex meth...memberVenkatesh Mookkan19 Jan '11 - 19:18 
Reason for my vote of 3
Why do someone use this complex method even though we can use simple and very easy method as stated below?
GeneralWhy do someone use this complex method even though we can si...memberVenkatesh Mookkan19 Jan '11 - 19:17 
Why do someone use this complex method even though we can simple and very easy method as stated below already exists?
GeneralFixed HTML encodingsubeditorIndivara19 Jan '11 - 18:28 
Fixed HTML encoding

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 20 Jan 2011
Article Copyright 2011 by Awais Hafeez 86
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid