所以我有一个包含菜单信息的分层数据源......我将它数据绑定到 ListView 并使用 CSS 将其格式化为菜单......一切都很好......现在下一步我似乎无法理解。 .
如何突出显示(设置类
这是我到目前为止所得到的,所以任何正确方向的提示都是好的。
<asp:ListView ID="lvMainOuter" runat="server">
<LayoutTemplate>
<ul id="menunav" runat="server">
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li <%# (Container.DataItem as FigLeafMenuItem).ItemSelected == "true" ? @" class=""MainMenuSelected""" : @" class=""""" %>>
<asp:HyperLink ID="nodeLink" runat="server" Text='<%# (Container.DataItem as FigLeafMenuItem).Name %>' NavigateUrl='<%# (Container.DataItem as FigLeafMenuItem).Url %>' />
<asp:ListView ID="lvMainInner" DataSource="<%# (Container.DataItem as FigLeafMenuItem).Children %>" runat="server">
<LayoutTemplate>
<ul id="menunav" runat="server">
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<li>
<asp:HyperLink ID="nodeLink" runat="server" Text='<%# (Container.DataItem as FigLeafMenuItem).Name %>' NavigateUrl='<%# (Container.DataItem as FigLeafMenuItem).Url %>' />
</li>
</ItemTemplate>
</asp:ListView>
</li>
</ItemTemplate>
</asp:ListView>
public int SelectedMenuId { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
lvMainOuter.ItemDataBound += lvMainOuter_ItemDataBound;
lvMainOuter.DataSource = new FigLeafMenu().GetFigLeafTopMenu();
lvMainOuter.DataBind();
}
void lvMainOuter_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
//WHAT DO I DO NOW TO GET THE SELECTED ITEM AND ASSIGN IT A CLASS?
}
}