久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ASP.NET MenuItem 個人樣式

ASP.NET MenuItem Individual Styles(ASP.NET MenuItem 個人樣式)
本文介紹了ASP.NET MenuItem 個人樣式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我希望使用 ASP.NET 菜單控件來瀏覽我的網(wǎng)站.但是,我要求每個 MenuItem 必須具有不同的樣式(不同的顏色,靜態(tài)和 onHover).如果不創(chuàng)建將從 MenuItem 繼承的自定義類,這可能嗎?

I'm hoping to use an ASP.NET Menu Control for navigation through my site. However, I've got a requirement that each MenuItem must be styled differently (different colors, both static, and onHover). Without creating a custom class that would inherit from MenuItem, is this possible?

有更好的解決方案嗎?

推薦答案

缺少覆蓋菜單上的 RenderContents,您的選擇非常有限.您需要的大部分內(nèi)容都是私密且密封的,您將無處可去.

Short of overriding RenderContents on Menu, your options are very limited. Most of what you'd need is private and sealed and you won't get anywhere there.

我的解決方案是使用模板.您可以使用 MenuItem.Value 或 Depth and ItemIndex 來標(biāo)識每個項(xiàng)目并提供必要的屬性.

My solution would be to use templates. You could use MenuItem.Value or Depth and and ItemIndex to identify each item and provide necessary attributes.

在頁面中:

<asp:Menu ID="menu" runat="server" DynamicHorizontalOffset="2" StaticSubMenuIndent="10px">
    <Items>
        <asp:MenuItem Text="Item 1" Value="value 1">
            <asp:MenuItem Text="Item 2" Value="value 2">
                <asp:MenuItem Text="Item 3" Value="value 3"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Item 4" Value="value 4">
                <asp:MenuItem Text="Item 5" Value="value 5"></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="Item 6" Value="value 6"></asp:MenuItem>
        </asp:MenuItem>
        <asp:MenuItem Text="Item 7" Value="value 7"></asp:MenuItem>
        <asp:MenuItem Text="Item 8" Value="value 8"></asp:MenuItem>
    </Items>
    <StaticItemTemplate>
        <asp:Panel runat="server" ForeColor='<%# GetItemColor(Container) %>'>
            <%# Eval("Text") %> - <%# Eval("Value") %>
        </asp:Panel>
    </StaticItemTemplate>
    <DynamicItemTemplate>
        <asp:Panel ID="Panel1" runat="server" ForeColor='<%# GetItemColor(Container) %>'>
            <%# Eval("Text") %> - <%# Eval("Value") %>
        </asp:Panel>
    </DynamicItemTemplate>
</asp:Menu>

在代碼中(不要介意這段代碼的愚蠢,只是為了演示原理):

In Code (never mind silliness of this code, it is just to demonstrate the principle):

public Color GetItemColor(MenuItemTemplateContainer container)
{
    MenuItem item = (MenuItem)container.DataItem;

    //identify based value
    if (item.Value == "value 2")
        return Color.Brown;

    //identify based on depth and index
    if (item.Depth == 0)
        switch (container.ItemIndex)
        {
            case 0: return Color.Red;
            case 1: return Color.Blue;
            case 2: return Color.DarkGreen;
            default:
                return Color.Black;
        }
    else
        switch (container.ItemIndex)
        {
            case 0: return Color.Purple;
            case 1: return Color.Aqua;
            case 2: return Color.DarkOrange;
            default:
                return Color.Black;
        }
}

這篇關(guān)于ASP.NET MenuItem 個人樣式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應(yīng)用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應(yīng)用程序 - 如何制作交互式菜單?)
How to add an icon to System.Windows.Forms.MenuItem?(如何向 System.Windows.Forms.MenuItem 添加圖標(biāo)?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
Building a database driven menu with ASP.NET, JQuery and Suckerfish(使用 ASP.NET、JQuery 和 Suckerfish 構(gòu)建數(shù)據(jù)庫驅(qū)動的菜單)
主站蜘蛛池模板: 日本国产欧美 | 国产理论在线 | 丰满少妇高潮在线观看 | 日韩伦理在线播放 | 在线色网站 | 青青久久久 | 日韩精品久久久 | 欧美一二| 亚洲另类视频 | 一区二区三区黄色 | 一区二区三区精品视频 | 欧美福利视频 | 乳色吐息在线观看 | av福利在线观看 | 日本欧美久久久久免费播放网 | 欧美一级淫片免费视频黄 | 免费视频一区 | 国产美女一区二区 | 91在线观看视频 | 日韩中文字幕在线观看 | 中文在线视频 | 在线观看日韩精品 | 欧美黄视频 | 国产精品美女久久久 | 日本午夜网站 | 国产一区二区日韩 | 国产又色又爽又黄又免费 | 国产欧美日韩综合 | 欧美精品三区 | 一区二区三区黄色 | 五月婷婷丁香综合 | 欧美激情久久久 | 国产a久久麻豆入口 | 中文字幕免费视频 | 日本特黄一级片 | 成人在线观看免费爱爱 | 日韩在线免费观看视频 | 免费观看全黄做爰的视频 | 青草av在线 | 欧美成人一区二区三区 | 青草av在线 |