|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
| |
| 使用CSS+SiteMap+UserControl+MasterPage实现简易的Tab |
|
我们在做网站后台管理的时候,往往需要用到Tab形式的导航菜单,博客园如此,BlogEngine也如此,前段时间研究修改BlogEngine的时候看到其Tab实现如此容易,思路不错,但是有一点使我郁闷,他的Tab标题是取文件名,而使用中文的文件名是写程序的大忌,自然就想到了 Asp.Net2.0的特性Web.sitemap,我们的数据源如何不从它来,于是简单写了下,其实很简单,只需要一个样式文件,一个SiteMap, 一个通用的UserControl,一个母版页。 b4xLinux联盟 b4xLinux联盟 b4xLinux联盟 b4xLinux联盟 下面是核心Code) b4xLinux联盟 protected void Page_Load(object sender, EventArgs e) b4xLinux联盟 { b4xLinux联盟 if (!Page.IsCallback) b4xLinux联盟 { b4xLinux联盟 BindMenu(); b4xLinux联盟 } b4xLinux联盟 } b4xLinux联盟 b4xLinux联盟 /// <summary> b4xLinux联盟 /// Binds the menu. b4xLinux联盟 /// </summary> b4xLinux联盟 private void BindMenu() b4xLinux联盟 { b4xLinux联盟 SiteMapNodeCollection smnc = SiteMap.CurrentNode.ParentNode.ChildNodes; b4xLinux联盟 b4xLinux联盟 foreach (SiteMapNode smn in smnc) b4xLinux联盟 { b4xLinux联盟 AddItem(smn.Title, smn.Url); b4xLinux联盟 } b4xLinux联盟 } b4xLinux联盟 b4xLinux联盟 /// <summary> b4xLinux联盟 /// Adds the item. b4xLinux联盟 /// </summary> b4xLinux联盟 /// <param name="text">The text.</param> b4xLinux联盟 /// <param name="url">The URL.</param> b4xLinux联盟 public void AddItem(string text, string url) b4xLinux联盟 { b4xLinux联盟 HtmlAnchor a = new HtmlAnchor(); b4xLinux联盟 a.InnerHtml = "<span>" + text + "</span>"; b4xLinux联盟 a.HRef = url; b4xLinux联盟 b4xLinux联盟 if (Request.RawUrl.EndsWith(url, StringComparison.OrdinalIgnoreCase)) b4xLinux联盟 a.Attributes["class"] = "current"; b4xLinux联盟 b4xLinux联盟 HtmlGenericControl li = new HtmlGenericControl("li"); b4xLinux联盟 li.Controls.Add(a); b4xLinux联盟 ulMenu.Controls.Add(li); b4xLinux联盟 } b4xLinux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论 |
|
|
|
|
|