我正在使用Sitecore,我有一个包含选项卡的网页。此选项卡可以有一个或多个子项。现在有了一个促销控件,它会根据所选的选项卡动态更改。
因此,如果我选择了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>
如何获取哪个页签被选中的信息。我将在一个单独的函数中更改促销控件:
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;
}我该怎么办?
发布于 2012-07-20 05:37:09
Text控件需要知道项目上下文。如果没有设置,它将假定您所在的当前上下文项,这将导致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;
}https://stackoverflow.com/questions/11569294
复制相似问题