我有 2 个选项卡作为带有一个链接的 Sitecore.Web.UI.WebControls.Link。现在当页面打开时,我想关注第一个。我写了这段代码,但似乎它只达到了第 0 个索引 2 次。所以我将两个选项卡都作为选定项目。这是代码:
protected void rptTab_ItemBound(Object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Item i = e.Item.DataItem as Item;
Link hlTabLink;
HtmlControl liHTML;
liHTML = e.Item.FindControl("liTabTest") as HtmlControl;
hlTabLink = e.Item.FindControl("hlTabLink") as Link;
hlTabLink.Target = Sitecore.Links.LinkManager.GetItemUrl(i);
hlTabLink.DataSource = i.Paths.FullPath;
hlTabLink.Field = "Title";
String liContainerId;
switch (hlTabLink.TabIndex) //Switch case statements for the tab navigation.
{
case 0:
liContainerId = "tab-label TabbedPanelsTabSelected";
liHTML.Attributes.Add("class", liContainerId);
break;
case 1:
liContainerId = "tab-label TabbedPanelsTabSelected";
hlTabLink.CssClass = "tab-label TabbedPanelsTabSelected";
break;
case 2:
liContainerId = "tab-label last";
hlTabLink.Attributes.Add("class", liContainerId);
break;
}
}
案例 0 击中 2 次。如您所见,选项卡位于转发器中。这是它的标记:
<asp:Repeater ID="rptTab" runat="server" OnItemDataBound="rptTab_ItemBound">
<ItemTemplate>
<li id= "liTabTest" runat = "server">
<a>
<sc:Link ID = "hlTabLink" Field = "scTabLink" runat ="server"></sc:Link>
</a>
</li>
</ItemTemplate>
</asp:Repeater>