Help with FieldListView
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"
/>
<
sf:OptionalLink
ID
=
"SourceUrl"
runat
=
"server"
NavigateUrlSource='<%# Eval("SourceSite")%>'
TextSource='<%# Eval("SourceName")%>'
TextTag="Source: "
/>
<
asp:HyperLink
id
=
"lnkSource"
runat
=
"server"
NavigateUrl='<%# Eval("SourceSite")%>' target="_blank"><%# Eval("SourceName")%></
asp:HyperLink
>
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>
SourceSite
should be wrapped inside HyperLink if you want to click on it.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
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
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
>
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
<
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" />
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
...
<
asp:HyperLink
ID
=
"MyHyperlink"
runat
=
"server"
NavigateUrl='<%# Eval("MyUrl")%>'
Text='<%# Eval("MyTitle") %>'
Visible='<%# (Eval("MyUrl") != null && Eval("MyUrl") != String.Empty) %>' />
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