Navigation actually gives visitors a map of something similar, allowing visitors to find what they want faster.
A very important concept introduced in 2.0 is the site Map sitemap, an XML file, but its suffix is not XML.
To create a consistent, easily managed navigation solution for your site, you can use ASP.net site navigation. ASP.net site navigation provides the following features:
After understanding some basic knowledge, let's do a simple navigation example.
1, first create a master
HTML code:
<%@ Master language= "C #" autoeventwireup= "true" codebehind= "Mp.master.cs" inherits= "navigation.mp"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <html xmlns=" http://www.w3.org/1999/xhtml "> <head runat=" Server "> <title></title> &L T;asp:contentplaceholder id= "Head" runat= "Server" > </asp:ContentPlaceHolder> </head> <body> ; form id= "Form1" runat= "Server" > <div> <table style= "width:656px"; height:255px "> <tr> <td style=" width:500px; Background-color: #99ccff > Your current location in: <asp:sitemappath id= "SiteMapPath1" runat= "Server" Font-name
s= "Verdana" font-size= "0.8em" pathseparator= ":" > <currentnodestyle forecolor= "#333333"/> <nodestyle font-bold= "true" forecolor= "#990000"/> <pathseparatorstyle font-bold= "true" forecolor= "#990000 "/> <rootnodestyle font-bold= "True" forecolor= "#FF8000"/> </asp:SiteMapPath> </td> </TR&G
T <tr> <td style= "width:500px" > <asp:contentplaceholder id= "ContentPlaceHolder1" runat= "Server" &G
T </asp:ContentPlaceHolder> </td> </tr> <tr> <td style= "width:500px; Background-color: #ebebff "> Copyright ..... </td> </tr> </table> </div> </form> </body> </html>
The effect displayed:
2, establish the following navigation structure (unified application above Master)
3, add site map (name can not be changed)
The code under Web.sitemap is as follows:
<?xml version= "1.0" encoding= "Utf-8"?> <sitemap xmlns= "http://schemas.microsoft.com/AspNet/" sitemap-file-1.0 "> <sitemapnode url=" a.aspx "title=" Home "description=" 1 "> <sitemapnode url=" b.aspx "title = "Root b page" description= "2"/> <sitemapnode url= "default.aspx" title= "Default page" description= "3"/> <sitemap Node url= "" title= "one Directory" description= "4" > <sitemapnode url= "~/one/a.aspx" title= "one Directory" a "description=" 5 "/ > <sitemapnode url= "~/one/b.aspx" title= "one Directory" B "description=" 6 "/> <sitemapnode" "url=" one directory of O nce directory "description=" 7 "> <sitemapnode url=" ~/one/once/a.aspx "title=" one directory under the once directory of a "description=" 8 "/> & B "Once" 9 "description= </siteMapNode>/> In the </site directory under the Lt;sitemapnode url=" ~/one/once/b.aspx "title=" one Directory mapnode> <sitemapnode url= "title=" two Directory "description=" "> <sitemapnode url=" ~/two/a.aspx "title=" two Recorded a "description="/> <sitemapnode urL= "~/two/b.aspx" title= "two directory of B" description= ""/> </siteMapNode> <sitemapnode url= "Sitemap.aspx" Ti Tle= "dynamically modify in-memory" description= "dynamically modify site Map in memory"/> </siteMapNode> </siteMap>
4, in the root directory a.aspx, put a TreeView control. Create a new data source for our site map.
After running, we can see the effect as shown in the figure:
Next will talk about dynamic changes in the memory of the site map, what is called dynamic Modification in the memory of the site map, in the end what is the meaning of it?
For example, there are often many articles in the list, we can not put these to the site map, not to mention the article ID, column number, commodity classification or Product ID is not in advance we can anticipate, then the site map does not, outside can not show, how to do? This requires the dynamic modification of the site map in memory.
As mentioned above, we assume that there is an article management system structure as follows:
Home-News-International News (list)
Then you can assume that the international news at this level of the page is list.aspx, different columns will have different IDs, then the address structure is assumed as follows:
Xxx.com--~/news/--list.aspx?id=3&page=12
Such a structure, our processing of the News list page can only be statically written on the site map url= "~/news/list.aspx". So if the above structure is displayed when others are browsing, then we deal with it.
Web.sitemap:
<?xml version= "1.0" encoding= "Utf-8"?> <sitemap xmlns= "http://schemas.microsoft.com/AspNet/" sitemap-file-1.0 "> <sitemapnode url=" a.aspx "title=" Home "description=" 1 "> <sitemapnode url=" b.aspx "title = "Root b page" description= "2"/> <sitemapnode url= "default.aspx" title= "Default page" description= "3"/> <sitemap Node url= "" title= "one Directory" description= "4" > <sitemapnode url= "~/one/a.aspx" title= "one Directory" a "description=" 5 "/ > <sitemapnode url= "~/one/b.aspx" title= "one Directory" B "description=" 6 "/> <sitemapnode" "url=" one directory of O nce directory "description=" 7 "> <sitemapnode url=" ~/one/once/a.aspx "title=" one directory under the once directory of a "description=" 8 "/> & B "Once" 9 "description= </siteMapNode>/> In the </site directory under the Lt;sitemapnode url=" ~/one/once/b.aspx "title=" one Directory mapnode> <sitemapnode url= "title=" two Directory "description=" "> <sitemapnode url=" ~/two/a.aspx "title=" two Recorded a "description="/> <sitemapnode urL= "~/two/b.aspx" title= "two directory of B" description= ""/> </siteMapNode> <sitemapnode url= "Sitemap.aspx" Ti Tle= "dynamically modify in-memory" description= "dynamically modify site Map in memory"/> </siteMapNode> </siteMap>
The
is primarily used to illustrate this sentence in the dynamic modification memory with title.
then place a SiteMapPath control in the presentation page sitemap.aspx, and note that the background code for the page whose rendercurrentnodeaslink is true (indicating that the current node is linked)
is set:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls; Namespace Navigation {Public partial class Sitemap:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {//First we register an event here, which means that the event is triggered when accessing the CurrentNode property sitemap.sitemapresolve+=new Sitemapresolveeventha
Ndler (Sitemap_sitemapresolve); SiteMapNode Sitemap_sitemapresolve (Object Sender,sitemapresolveeventargs e) {//Our custom processing gets and creates a copy of the current node and copies it at the same time
The parent node SiteMapNode CurrentNode = SiteMap.CurrentNode.Clone (true);
SiteMapNode Tempnode = CurrentNode;
int id = nid ();
int page = Npage (); Get the variable if (id>0) {Tempnode.url = Tempnode.url + "? id=" + ID from the following method.
ToString (); } if (id>0 && page>=0) {Tempnode.url = Tempnode.url + "&page=" + page.
ToString (); else if (page>0) {Tempnode.url = Tempnode.url + "? PagE= "+ page.
ToString ();
return tempnode;
//randomly set a number.
private int nid () {return 3;
private int Npage () {return 12; }
}
}
Explanation: The above nid () and Npage () are the two methods used to obtain the parameters, which are actually based on the actual situation.
Run, let's look at the properties of this link:
To this, we are very simple to implement the dynamic modification of the site map in memory!
Site navigation, we are very commonly used in the development of BS, so we still have a deep grasp of the need, and then will send related articles, with you a discussion of learning!