Use RadBinaryImage as a hyperlink button

3 posts, 0 answers
  1. John Hadjioannou
    John Hadjioannou avatar
    30 posts
    Member since:
    Dec 2005

    Posted 04 Jul 2009 Link to this post

    I'm using a RadBinaryImage in a repeater to display a list of images from a db table.  I'd like to make the images "clickable", redirecting to a url specified in the database row.  Is there a way of setting the ImageUrl of a hyperlink to the RadBinaryImage - or some other way of achieving this?

    Thanks
    John
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 06 Jul 2009 Link to this post

    Hello John,

    This can be done by wrapping the RadBinaryImage instance inside an anchor tag and specifying the href of the anchor using a binding expression, for example:

            <asp:Repeater runat="server" ID="Repeater1" DataSourceID="SqlDataSource2">  
                <ItemTemplate> 
                    <fieldset style="float: left; width: 350px; height: 150px;">  
                        <legend><b>Company Name</b>:  
                            <%#Eval("CompanyName")%></legend>  
                        <div class="details">  
                            <div class="photo-container">  
                              <a href='<%# Eval("<SourceFieldUrl>")%>'>  
                                <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("Photo") %>' 
                                    AutoAdjustImageControlSize="false" Width="90px" Height="110px" ToolTip='<%#Eval("ContactName", "Photo of {0}") %>' 
                                    AlternateText='<%#Eval("ContactName", "Photo of {0}") %>' /> 
                               </a>
                            </div> 
                            <div class="data-container">  
                                <ul> 
                                    <li> 
                                        <label> 
                                            Contact Name:</label> 
                                        <%#Eval("ContactName")%> 
                                    </li> 
                                    <li> 
                                        <label> 
                                            Title:</label> 
                                        <%#Eval("ContactTitle")%> 
                                    </li> 
                                    <li> 
                                        <label> 
                                            City:</label> 
                                        <%#Eval("City")%> 
                                    </li> 
                                    <li> 
                                        <label> 
                                            Country:</label> 
                                        <%#Eval("Country")%> 
                                    </li> 
                                    <li> 
                                        <label> 
                                            Phone:</label> 
                                        <%#Eval("Phone")%> 
                                    </li> 
                                </ul> 
                            </div> 
                        </div> 
                    </fieldset> 
                </ItemTemplate> 
            </asp:Repeater> 
            <div style="clear: both;">  
            </div> 
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" 
                ProviderName="<%$ ConnectionStrings:TelerikConnectionString.ProviderName %>" 
                SelectCommand="SELECT TOP 6 * FROM [CustomerPhotos]"></asp:SqlDataSource> 
     

    where <SourceFieldUrl> is the name of the database field which holds the url.

    Best regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John Hadjioannou
    John Hadjioannou avatar
    30 posts
    Member since:
    Dec 2005

    Posted 06 Jul 2009 Link to this post

    Thank you!

    John
Back to Top