+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Help with FieldListView

Help with FieldListView

8 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    14 Jan 2011
    Link to this post
    Hi there,

    I'm trying to work with some of the date for both News and Events in the templates. I can display simple things as they come out of the box but I'm trying to use the provided controls to do some text formatting and can't seem to figure it out nor can I find any documentation. 

    One example is for news I want to display the source url as a hyperlink with the SourceName as the text and SourceSite as the NavigateUrl. My thought was that the following would work:
    <sf:FieldListView ID="SourceUrl" runat="server"
        Format="<strong>Source:</strong> <a href='{0}' target='_blank'>{1}</a>"
        Properties="SourceSite, SourceName"
        WrapperTagName="div"
    />
    But it doesn't display anything. Am I missing something from the above? I did some more digging and came arcoss the control OptionalLink and attempted the following:
    <sf:OptionalLink ID="SourceUrl" runat="server"
        NavigateUrlSource='<%# Eval("SourceSite")%>'
        TextSource='<%# Eval("SourceName")%>'
        TextTag="Source: "
        />
    Again, nothing gets displayed. What am I doing wrong?

    As a temporary solution I've gone with 
    <asp:HyperLink id="lnkSource" runat="server" NavigateUrl='<%# Eval("SourceSite")%>' target="_blank"><%# Eval("SourceName")%></asp:HyperLink>

    Which works but what I really want to be able to have is the text "Source: " displayed before the link but I only want it to appear if the values for SourceSite and SourceName have been set. Is this possible with the built in controls or do I have to create yet even more custom controls?

    I also have similar requirements for Start and End dates with events but if I could just get pointed in the right direction for the above that should get me going.

    Thanks in advance,
    Cheers,
    Phill
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    14 Jan 2011
    Link to this post
    Hi Phill,

    You can use TextField control

    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("SourceName")%>' />
    <asp:HyperLink runat="server" NavigateUrl='<%# Eval("SourceSite")%>' id="Test">
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("SourceSite")%>' />
    </HyperLink>


    The SourceSite should be wrapped inside HyperLink if you want to click on it.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    14 Jan 2011
    Link to this post
    Hi Ivan,

    Your suggestion is close but it doesn't quite answer my request. You're solution gives me:

    CNN News CNN News

    when what I want is:

    Source: CNN News

    I want the actual word "Source" or any text for that matter as a label for the sourcesite/sourcename data. Again if the item doesn't have any data defined for sourcesite/sourcename then I don't want the label text to appear.

    Are there any options or do I have to write a custom control?

    Regards,
    Phill
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    14 Jan 2011
    Link to this post
    Hello Phill,

    You have to customize the RadListView and show/hide the "Source" depending on whether there is a value for the HyperLink or not.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. David
    David avatar
    99 posts
    Registered:
    06 Sep 2012
    07 Nov 2011
    Link to this post
    Didn't work for me. Got a "Error parsing the template" messaage. I replaced the read more link with the suggested snipper.

    <asp:HyperLink runat="server" NavigateUrl='<%# Eval("SourceSite")%>' id="Test">
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("SourceSite")%>' />
    </HyperLink>




    <%@ Control Language="C#" %>
    <%@ 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" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit" Assembly="Telerik.Sitefinity" %>
      
    <telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <LayoutTemplate>
            <sf:ContentBrowseAndEditToolbar ID="MainBrowseAndEditToolbar" runat="server" Mode="Add"></sf:ContentBrowseAndEditToolbar>
            <ul class="sfnewsList sfnewsListTitleDateSummary">
                <asp:PlaceHolder ID="ItemsContainer" runat="server" />
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <li class="sfnewsListItem">
                <h2 class="sfnewsTitle">
                    <sf:DetailsViewHyperLink ID="DetailsViewHyperLink1" TextDataField="Title" ToolTipDataField="Description" runat="server" />
                </h2>
                <div class="sfnewsMetaInfo">
                    <sf:FieldListView ID="PublicationDate" runat="server" Format="{PublicationDate.ToLocal():MMM dd, yyyy}" />
                </div>
      
                <sf:FieldListView ID="summary" runat="server" Text="{0}" Properties="Summary" WrapperTagName="div" WrapperTagCssClass="sfnewsSummary"  /> 
      
    <asp:HyperLink runat="server" NavigateUrl='<%# Eval("SourceSite")%>' id="Test">
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("SourceSite")%>' />
    </HyperLink>
      
                <sf:ContentBrowseAndEditToolbar ID="BrowseAndEditToolbar" runat="server" Mode="Edit,Delete,Unpublish"></sf:ContentBrowseAndEditToolbar>
            </li>
        </ItemTemplate>
    </telerik:RadListView>
    <sf:Pager id="pager" runat="server"></sf:Pager>
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    08 Nov 2011
    Link to this post
    Hello David,

    Is is working now or you keep getting the error related to the parsing of the template. If the problem persists could you tell us which version you use and what is the current code of your template. If you can send the stack trace here, this will also help.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  7. Antoine
    Antoine avatar
    45 posts
    Registered:
    13 Jul 2012
    09 Feb 2012
    Link to this post

    Hi Ivan

    Am I misunderstanding the intended functionality of the FieldListView?  It seems like one or both of the following should work:

    <sf:FieldListView
        ID="MyHyperlink"
        runat="server"
        Text="Label: <a href='{0}'>{1}P</a>"
        Properties="MyUrl,MyTitle"
        WrapperTagName="div" />

    <sf:FieldListView
        ID="MyHyperlink"
        runat="server"
        Format="Label: <a href='{0}'>{1}P</a>"
        Properties="MyUrl,MyTitle"
        WrapperTagName="div" />

    In the first case, i get an exception:
    Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
     
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
     
    Source Error:
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
     
    Stack Trace:
     
     
    [FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.]
       System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args) +12643700
       System.String.Format(IFormatProvider provider, String format, Object[] args) +123
       Telerik.Sitefinity.Web.UI.FieldListView.OnDataBinding(EventArgs e) +396
       ...

    In the second case, the control simply outputs the two properties separated by a comma.

    I was able to somewhat work around the issue by using the following:
    <asp:HyperLink
        ID="MyHyperlink"
        runat="server"
        NavigateUrl='<%# Eval("MyUrl")%>'
        Text='<%# Eval("MyTitle") %>'
        Visible='<%# (Eval("MyUrl") != null && Eval("MyUrl") != String.Empty) %>' />
    This is not a perfect solution because it does not address hiding of labels or wrapper tags if no value is present, but perhaps it might help someone out there.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    15 Feb 2012
    Link to this post
    Hello,

    Format works only with properties ( shows property values) of the data item you bind. Behind the scene the code uses TypeDescriptor.GetProperties(this.dataItem).Find(propertyName)

    All the best,
    Ivan Dimitrov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

8 posts, 0 answered