Datasource in Repeater in Sitecore

烂漫一生 提交于 2019-12-11 08:26:11

问题


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.



来源:https://stackoverflow.com/questions/11215904/datasource-in-repeater-in-sitecore

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!