Linkbutton with image and text

I ran across the need to have a linkbutton that contained an image and text. A little background... I was creating a file structure-like list in a repeater control.  Each row had to be clickable by the folder name or folder icon; just like in Windows Explorer.

By default, the linkbutton has a Text property but this was of no help for trying to also squeeze in an image too.  But did you know you could do this with a linkbutton:

<asp:LinkButton ID="lbYear" runat="server" CausesValidation="false">

<asp:Image ID="imgFolder" runat="server" ImageUrl="~/images/folder.jpg" />

<%# Container.DataItem %>

</asp:LinkButton>

 

Here you see the LinkButton control acts like a template for the image control and text it needed to display.
Seriously, I know this isn't rocket science but it took me a few minutes to think about how this works because how often do you do this with the linkbutton control?  Enjoy!

32 Comments

Comments have been disabled for this content.