我在这里有一个非常基本的网站核心问题。我想遍历一组子对象(位置),并显示有关每个子对象的一些信息。
我正在使用 ASP 中继器进行迭代,我正在加载页面上的孩子,并且我正在尝试使用 sc 标签来显示信息 - 但我没有出现在页面上.
谁能帮我看看我在这里缺少什么?
后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
var item = Sitecore.Context.Item;
var children = new List<Sitecore.Data.Items.Item>();
foreach (var child in item.GetChildren())
{
children.Add((Sitecore.Data.Items.Item)child);
}
LocationsRpt.DataSource = children;
LocationsRpt.DataBind();
}
标记:
<asp:Repeater runat="server" ID="LocationsRpt" OnItemDataBound="LocationsRptItemDataBound">
<ItemTemplate>
<div class="InnerContentSec clearfix">
<div id="AboutSolar" class="AboutSolar clearfix">
<div class="items">
<h3>
<sc:Text runat="server" ID="Title"/>
</h3>
<div class="LocationBlock clearfix">
<div class="ImgSec">
<sc:Image id="Image" runat="server" Width="185" Height="107" />
</div>
<div class="DescSec">
<p><sc:Text ID="ShortDescription" runat="server" /></p>
</div>
</div>
</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
而且,最后在 DataItemBound 上
protected void LocationsRptItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
var subItem = e.Item.DataItem as Item;
if (subItem != null)
{
var appTitle = e.Item.FindControl("Title") as Sitecore.Web.UI.WebControls.Text;
if (appTitle != null)
{
appTitle.DataSource = subItem.ID.ToString();
appTitle.Field = "Application Title";
appTitle.DataBind();
}
var appImage = e.Item.FindControl("Image") as Sitecore.Web.UI.WebControls.Image;
if (appImage != null)
{
appImage.DataSource = subItem.ID.ToString();
appImage.Field = "Location Image";
appImage.DataBind();
}
var shortDescription = e.Item.FindControl("ShortDescription") as Sitecore.Web.UI.WebControls.Text;
if (shortDescription != null)
{
shortDescription.DataSource = subItem.ID.ToString();
shortDescription.Field = "Short Description";
shortDescription.DataBind();
}
}
}
}