When we perform website background management, we often need to use the tab-based navigation menu. This is true for the blog garden and blogengine. Some time ago, when we studied and modified blogengine, we saw that its tab implementation was so easy, A good idea, but one thing depressing me, his tab title is to take the file name, while the Chinese file name is to write Program Naturally, ASP comes to mind. net2.0 features web. sitemap: How does our data source not come from it? So we simply write it down. In fact, we only need a style file, a sitemap, a general usercontrol, and a master page.
Below is the core 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 SMNInSmnc)
{
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 = New Htmlanchor ();
A. innerhtml = " <Span> " + Text + " </Span> " ;
A. href = URL;
If (request. rawurl. endswith (URL, stringcomparison. ordinalignorecase)
. attributes [ " class " ] = " current " ;
Htmlgenericcontrol Li= NewHtmlgenericcontrol ("Li");
Li. Controls. Add ();
Ulmenu. Controls. Add (LI );
}
Running effect:
Download source code: Web projecttab.zip
Web site tab.rar