Datasource in Repeater in Sitecore

2019-08-09 00:23发布

问题:

I have the following inside a repeater;

<sc:Link runat="server" DataSource='<%# (Container.DataItem as Item).Paths.Path %>' TextField="Title" LinkField="Title" />

This however fails. I have also tried with

<sc:Link runat="server" DataSource='<%# Container.DataItem %>' TextField="Title" LinkField="Title" />

Which also fails. What am i missing?

回答1:

Try setting Item parameter instead of DataSource. I don't have many sc:Link controls in my code, but here is one I know works:

<sc:Link  ID="hlMore" runat="server" Item='<%# Container.DataItem %>' Field="ImageLink" Text=<%# Sitecore.Globalization.Translate.Text("FindOutMore") %>></sc:Link>

Note it also uses "Field" and not TextField. Hmmmm. In the code behind, the data source is a List collection.

Here's another one, with a control inside it:

<sc:Link ID="lnkFlag" runat="server" Field="FlagLink" Item='<%# Container.DataItem %>'>
    <sc:Image runat="server" Field="FlagImage" Item='<%# Container.DataItem %>' />
</sc:Link>


回答2:

DataSource should be ID, not item or item.Path.

Item should be the datasource item.



标签: sitecore