1

ここでかなり基本的なサイトコアの質問があります。子オブジェクト (場所) のグループを繰り返し処理し、それぞれに関する情報を表示したいと考えています。

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();
                }
            }
        }
    }
4

2 に答える 2

9

次のようにすることもできます。

ページロード:

protected void Page_Load(object sender, EventArgs e)
{
    LocationsRpt.DataSource = Sitecore.Context.Item.GetChildren();
    LocationsRpt.DataBind();
}

マークアップ:

<asp:Repeater runat="server" ID="LocationsRpt">
    <ItemTemplate>
        <div class="InnerContentSec clearfix">
            <div id="AboutSolar" class="AboutSolar clearfix">
                <div class="items">
                <h3>
                    <sc:Text runat="server" ID="Title" Item="<%# Container.DataItem %>"/>
                </h3>
                <div class="LocationBlock clearfix">
                <div class="ImgSec">
                    <sc:Image id="Image" runat="server" Width="185" Height="107"  Item="<%# Container.DataItem %>" />
                </div>
                <div class="DescSec">
                    <p><sc:Text ID="ShortDescription" runat="server"  Item="<%# Container.DataItem %>" /></p>
                </div>
                </div>
                </div>
            </div>
        </div>
    </ItemTemplate>
</asp:Repeater>

この場合、データバインド イベントは必要ありません。

于 2013-05-15T14:05:42.493 に答える
2

私は速すぎました。私が返信した後、あなたはイベントハンドラ コードを追加しました。

Itemイベントハンドラで、フィールド コントロールのプロパティを設定する必要があります。たとえば、次のようになります。appTitle.Item = item

また、これらのコントロールに対して DataBind() を呼び出す必要はありません。

また、item.GetChildren()リピーターのデータソースとして使用できます。子を新しいリストにコピーする必要はありません。

于 2013-05-15T13:50:33.697 に答える