惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
雷峰网
雷峰网
博客园_首页
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
小众软件
小众软件
D
Docker
P
Proofpoint News Feed
B
Blog
Vercel News
Vercel News
B
Blog RSS Feed
U
Unit 42
月光博客
月光博客
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
I
InfoQ
Recent Announcements
Recent Announcements

博客园 - 冰戈

【解决方法】IIS 承载的服务失败 - 冰戈 - 博客园 【Silverlight】使用ChildWindow实现MessageBox 【Silverlight】利用IsolatedStorageFile实现客户端缓存 Silverlight3_Tools&SDK发布中文版 Windows Server 2008 将与 Visual Studio 2008 以及 SQL Server 2008 共同发布 基于Ajax的模糊查询输入控件(补充) 基于Ajax的编码、拼音缩写、名称模糊查询输入控件 个人站点域名改为www.oylb.net 使用PostSharp进行AOP框架设计:一个简单的原型 又一套BlogEngine主题Andreas 给博客增加了一个主题Nautica02Liquid 对BlogEngine进行了一次简单升级 SQL Server 2005公用表达式实现递归 微软2008系列 (Orcas + Longhorn Server+SQL2008)将于2008年2月27日发布 - 冰戈 转实用文章:常用开源协议详细解析 SubSonic 命令行参数及使用示例 抢先试用ReSharper UnitRun™ 1.0 又一款免费的VS2005单元测试插件 公司求才,你们是怎样做的?你想怎样做?
使用CSS+SiteMap+UserControl+MasterPage实现简易的Tab
冰戈 · 2007-07-04 · via 博客园 - 冰戈

我们在做网站后台管理的时候,往往需要用到Tab形式的导航菜单,博客园如此,BlogEngine也如此,前段时间研究修改BlogEngine的时候看到其Tab实现如此容易,思路不错,但是有一点使我郁闷,他的Tab标题是取文件名,而使用中文的文件名是写程序的大忌,自然就想到了Asp.Net2.0的特性Web.sitemap,我们的数据源如何不从它来,于是简单写了下,其实很简单,只需要一个样式文件,一个SiteMap,一个通用的UserControl,一个母版页。

下面是核心Code)

protected void Page_Load(object sender, EventArgs e)
        {
            
if (!Page.IsCallback)
            {
                BindMenu();
            }
        }
    

        
/// <summary>
        
/// Binds the menu.
        
/// </summary>
        private void BindMenu()
        {
            SiteMapNodeCollection smnc 
= SiteMap.CurrentNode.ParentNode.ChildNodes;foreach (SiteMapNode smn in smnc)
            {
                AddItem(smn.Title, smn.Url);
            }
        }
/// <summary>
        
/// Adds the item.
        
/// </summary>
        
/// <param name="text">The text.</param>
        
/// <param name="url">The URL.</param>
        public void AddItem(string text, string url)
        {
            HtmlAnchor a 
= new HtmlAnchor();
            a.InnerHtml 
= "<span>" + text + "</span>";
            a.HRef 
= url;if (Request.RawUrl.EndsWith(url, StringComparison.OrdinalIgnoreCase))
                a.Attributes[
"class"= "current";

            HtmlGenericControl li 

= new HtmlGenericControl("li");
            li.Controls.Add(a);
            ulMenu.Controls.Add(li);
        }

运行效果:

image

源码下载:web projectTab.zip
          web site Tab.rar