1

我的母版页中有一个非常大的无序列表项。说它包含 60 多个列表项。根据某些情况,我想隐藏该列表项(隐藏项可能是 1 到 59 )

我的主文件代码片段:

<li><a href="#">Authorization</a>
    <ul>
        <li><a href="NewCardGeneration.aspx"><span>Card Request</span></a></li>
        <li><a href="cardIssueAuth.aspx"><span>Card Issue</span></a></li>
        <li><a href="CardReloadAuth.aspx"><span>Card Reload</span></a></li>
        <li><a href="CloseCardAuth.aspx"><span>Close Card</span></a></li>
        <li><a href="CardReplacementAuth.aspx"><span>Card Replacement</span></a></li>
        <li><a href="CardStatuschangeAuth.aspx"><span>Card Status Change</span></a></li>
        <li><a href="UpgradeDowngradeAuth.aspx"><span>Upgrade/DownGrade</span></a></li>
    </ul>
</li>

健康)状况 : -

我的DataTable回报值像

cardIssueAuth.aspx
Distributor.aspx
CardStatuschangeAuth.aspx
UpgradeDowngradeAuth.aspx

所以我只想隐藏那些进来的页面DataTable

我知道 & 的ID &runat属性<li>然后让它visible : false

但是我怎样才能有效/动态地使用它呢?通过使用一些 for 循环 ...!!

4

2 回答 2

1

I personally donot like the 'visibility' hack. You could selectively render the 'li' elements on the server-side itself (via code-behind or scriptlets) based on the entries on DataTable.

On the code-behind, you could have a static dictionary that contains all the link details, grouped by sections. Plus the filtering logic:

        var sections = new List<Section>()
                           {
                               new Section()
                                   {
                                       Header = "Authorization",
                                       SubLinkDetails = new Dictionary<string, string>()
                                                        {
                                                            {"NewCardGeneration.aspx", "Card Request"},
                                                            {"cardIssueAuth.aspx", "Card Issue"},
                                                            //.. and so on
                                                        }
                                   }
                               //.. other sections follow
                           };

        //filter subLinkDetails depending on the DataTable entries
        sections.ForEach(s => s.SubLinkDetails.RemoveWhere(k => DataTable.Contains(k)));

Here, the Section is a convenience class and RemoveWhere is an extension method on IDictionary:

    class Section
    {
        public string Header { get; set; }
        public IDictionary<string,string> SubLinkDetails { get; set; }
    }
    public static class IDictionaryX
    {
        public static void RemoveWhere<K,V>(this IDictionary<K,V> dictionary, Predicate<K> condition)
        {
            IEnumerable<K> keysToRemove = dictionary.Keys.Where(k => condition(k));
            foreach (var k in keysToRemove)
            {
                 dictionary.Remove(k);
            }
        }
    }

In your aspx, access the sections and render the ul/li elements:

        <%foreach (var section in sections)
        {%>
            <li><a href="#"><%=section.Header %></a>
            <%foreach (var filteredLink in section.SubLinkDetails)
            {%>
                <li><a href="<%= filteredLink.Key>"><span>"<%= filteredLink.Value>"</span></a></li>
            <%}%>
            </li>
        <%}%>
于 2013-06-01T07:41:42.653 回答
0

<li>根据页面名称为您提供 id 。

接着,

你可以这样做

if (listItem.selectedItem == 'pagename.aspx')
    this.hide.style.Add("display", "none");
于 2013-06-01T07:39:46.390 回答