首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Sitecore中获取“Tab”索引

问在Sitecore中获取“Tab”索引
EN

Stack Overflow用户
提问于 2012-07-20 05:05:55
回答 1查看 445关注 0票数 0

我正在使用Sitecore,我有一个包含选项卡的网页。此选项卡可以有一个或多个子项。现在有了一个促销控件,它会根据所选的选项卡动态更改。

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

到目前为止,我得到的只是以下代码:

代码语言:javascript
复制
        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个选项卡。这些选项卡在中继器中如下所示:

代码语言:javascript
复制
<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>

​

如何获取哪个页签被选中的信息。我将在一个单独的函数中更改促销控件:

代码语言:javascript
复制
 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;
    }

我该怎么办?

EN

回答 1

Stack Overflow用户

发布于 2012-07-20 05:37:09

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

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

代码语言:javascript
复制
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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11569294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档