Help with FieldListView

Posted by Community Admin on 05-Aug-2018 07:02

Help with FieldListView

All Replies

Posted by Community Admin on 14-Jan-2011 00:00

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

Posted by Community Admin on 14-Jan-2011 00:00

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.

Posted by Community Admin on 14-Jan-2011 00:00

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

Posted by Community Admin on 14-Jan-2011 00:00

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.

Posted by Community Admin on 07-Nov-2011 00:00

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>

Posted by Community Admin on 08-Nov-2011 00:00

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 >>

Posted by Community Admin on 09-Feb-2012 00:00


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'>1P</a>"
    Properties="MyUrl,MyTitle"
    WrapperTagName="div" />

<sf:FieldListView
    ID="MyHyperlink"
    runat="server"
    Format="Label: <a href='0'>1P</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.

Posted by Community Admin on 15-Feb-2012 00:00

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 >>

This thread is closed