【问题标题】:Getting the 'Tab' Index in Sitecore在 Sitecore 中获取“标签”索引
【发布时间】:2012-07-19 21:05:54
【问题描述】:

我正在使用 Sitecore,并且我有一个包含选项卡的网页。此选项卡可以有 1 个或多个子项。现在有一个促销控件,它会根据选择的选项卡而动态变化。

因此,如果我选择了 Tab1,那么该页面将显示一些促销信息。 Tab2 可能有不同/相同的促销。这两个被放置在不同的控件中。

到目前为止,我得到的只是这段代码:

        Sitecore.Data.Database db = Sitecore.Context.Database;
        Item home = db.GetItem(Sitecore.Context.Site.StartPath);
        var getItems = (from Item item in currItem.Children.InnerChildren 
                        select item).ToList();

此查询的结果是 3 个项目。因为有 3 个选项卡。这些标签在转发器中是这样的:

<asp:Repeater ID="rptPromo" runat="server" OnItemDataBound="rptPromo_ItemBound">
<ItemTemplate>
    <table width="100%">
          <tbody>
                 <tr>

                     <td>
                         <h2><sup><sc:Text ID="txtPromo" Field="PromoText" runat="server" /></sup></h2>
                    </td>

                 </tr>

           </tbody>
    </table>    
</ItemTemplate>

如何获取选择了哪个选项卡的信息。我正在单独的函数中更改 PROMO 控件:

 protected void rptPromo_ItemBound (Object sender, RepeaterItemEventArgs e)
    {

        Item i = e.Item.DataItem as Item;
        Text txtPromo = e.Item.FindControl("txtPromo") as Text;
        //txtPromo.Attributes.Add("txtPromo", txtPromo);
        //HTMLControl hyperLinkLookUp = e.Item.FindControl("") as 
        string s;
    }

我该怎么办?

【问题讨论】:

    标签: c# asp.net sitecore


    【解决方案1】:

    Text 控件需要知道 Item 上下文。如果未设置,则假定您所在的当前上下文项将导致 3 个重复的 PromoTexts 出现在转发器中(如果 PromoText 字段未出现在当前上下文项上,则根本没有)。

    您已经在 Text 控件上定义了Field 属性,因此您只需按如下方式分配其Item 属性:

    protected void rptPromo_ItemBound (Object sender, RepeaterItemEventArgs e)
    {
        Item i = e.Item.DataItem as Item;
        Sitecore.Web.UI.WebControls.Text txtPromo = e.Item.FindControl("txtPromo") as Sitecore.Web.UI.WebControls.Text;
        txtPromo.Item = i;
    
        //txtPromo.Attributes.Add("txtPromo", txtPromo);
        //HTMLControl hyperLinkLookUp = e.Item.FindControl("") as 
        string s;
    }
    

    【讨论】:

    • 在哪里?这不能回答我的问题!
    • 我已经更新了我的答案。也许你应该重申你的问题。有点不清楚您要做什么。
    • txtPromo 没有名为“项目”的属性。
    • 我很确定确实如此。 sc:Text 控件存在于 Sitecore.Web.UI.WebControls.Text 您可能是从其他一些类继承的。试试Sitecore.Web.UI.WebControls.Text txtPromo = e.Item.FindControl("txtPromo") as Sitecore.Web.UI.WebControls.Text;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多