0

所以我有一个包含菜单信息的分层数据源......我将它数据绑定到 ListView 并使用 CSS 将其格式化为菜单......一切都很好......现在下一步我似乎无法理解。 .

如何突出显示(设置类

  • ) 刚刚选择的菜单项.. 它们只是链接.. 我是否应该以某种方式识别所单击内容的 ID,然后使用它以某种方式循环遍历..?

    这是我到目前为止所得到的,所以任何正确方向的提示都是好的。

     <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? 
        }
    }
    
  • 4

    2 回答 2

    1

    Try this

            <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>
            <SelectedItemTemplate>
                <li>
                    <asp:HyperLink ID="nodeLink" CssClass="MyHighlightClass" runat="server" Text='<%# (Container.DataItem as FigLeafMenuItem).Name %>'
                        NavigateUrl='<%# (Container.DataItem as FigLeafMenuItem).Url %>' />
                </li>
            </SelectedItemTemplate>
        </asp:ListView>
    

    or you could use codebehind ...

       lvMainInner.SelectedIndexChanged += (o, args) =>
                {
                  //You can do whatever here
                };
    
    于 2012-10-10T19:16:56.170 回答
    0

    在您的超链接标记中,您可以将CssClass设置为基于某些语句的条件语句,对吗?

    于 2012-10-10T17:09:32.967 回答