More in this section

Forums / Developing with Sitefinity / image linking to document

image linking to document

2 posts, 0 answered
  1. Martin
    Martin avatar
    6 posts
    14 Sep 2012
    16 Sep 2012
    Link to this post
    I have created a custom module.  This includes an image field + a document link field.  I would like users to be able to click on the image within list view  to open the document is this possible?
  2. Randy Hodge
    Randy Hodge avatar
    96 posts
    03 Nov 2014
    20 Sep 2012
    Link to this post
    Hi Martin,

    What I would recommend is to use an external template which will allow you to use code-behind file and determine the logic for title and Image size. For more information on using external templates in Sitefinity, please check this blog post.

    Here is a sample template for one of my modules made to be like yours demonstrating this functionality, please feel free to modify it as you find appropriate.

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OpenAccessDataProvider,00e728290c074858805c8efeb8624555.ascx.cs" Inherits="SitefinityWebApp.Templates.MyDocs.OpenAccessDataProvider_00e728290c074858805c8efeb8624555" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Fields" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <telerik:RadListView ID="dynamicContentListView" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
            <ul class="sfitemsList sfitemsListTitleDateTmb">
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            <li class="sfitem sfClearfix">
                <asp:HyperLink ID="ImageLink" runat="server" Target="_blank" />
                <h2 class="sfitemTitle">
                    <sf:DetailsViewHyperLink ID="DetailsViewHyperLink" TextDataField="Title" runat="server" />
                <sf:FieldListView ID="PublicationDate" runat="server" Format="{PublicationDate.ToLocal():MMM d, yyyy, HH:mm tt}" WrapperTagName="div" WrapperTagCssClass="sfitemPublicationDate" />
    <sf:Pager id="pager" runat="server"></sf:Pager>
    <asp:PlaceHolder ID="socialOptionsContainer" runat="server"></asp:PlaceHolder>

    and the codebehind
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using Telerik.Sitefinity.Model;
    using Telerik.Sitefinity.DynamicModules.Model;
    using Telerik.Sitefinity.Model.ContentLinks;
    using Telerik.Sitefinity;
    using Telerik.Sitefinity.Web.UI.ContentUI;
    namespace SitefinityWebApp.Templates.MyDocs
        public partial class OpenAccessDataProvider_00e728290c074858805c8efeb8624555 : System.Web.UI.UserControl
            protected void Page_Load(object sender, EventArgs e)
                this.dynamicContentListView.ItemDataBound += new EventHandler<Telerik.Web.UI.RadListViewItemEventArgs>(dynamicContentListView_ItemDataBound);
            void dynamicContentListView_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
                if (e.Item.ItemType == RadListViewItemType.DataItem || e.Item.ItemType == RadListViewItemType.AlternatingItem)
                    var dataItem = e.Item as RadListViewDataItem;
                    if (dataItem.DataItem != null)
                        var item = dataItem.DataItem as DynamicContent;
                        if (item != null)
                            var img = item.GetValue<ContentLink[]>("DocImage").FirstOrDefault().ChildItemId;
                            var imgUrl = App.WorkWith().Image(img).Get().ThumbnailUrl;
                            var link = e.Item.FindControl("ImageLink") as HyperLink;
                            if (link != null)
                                link.ImageUrl = imgUrl;
                                var docItem = Guid.Empty;
                                    docItem = item.GetValue<ContentLink[]>("DocLink").FirstOrDefault().ChildItemId;
                                catch { }
                                if (docItem != null && docItem != Guid.Empty)
                                    var docUrl = App.WorkWith().Document(docItem).Get().MediaUrl;
                                                                    link.NavigateUrl = docUrl;

    Randy Hodge
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered