The Application of site maps is still common. Even a simple personal homepage has a site map. Let's make a small example today. It only serves as an example.
First, add a web. sitemap. Note that the file name is not changed here. Add the following code:
<? XML version = "1.0" encoding = "UTF-8"?> <Sitemap xmlns = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"> <sitemapnode url = ". aspx "Title =" Homepage "Description =" Click here to return to the Homepage "> <sitemapnode url =" B. aspx "Title =" root directory B page "Description =" Click here to return to home "/> <sitemapnode url =" kongjian1.aspx "Title =" Concept Page "Description =" "/> <sitemapnode url = "" Title = "first subdirectory" Description = ""> <sitemapnode url = "~ /One/a. aspx "Title =" first subdirectory a page "Description =" "/> <sitemapnode url = "~ /One/B. aspx "Title =" first subdirectory B page "Description =" "/> </sitemapnode> <sitemapnode url =" "Title =" one directory subdirectory "Description =" "> <sitemapnode url = "~ /One/cone/a. aspx "Title =" one sub-directory a "Description =" "/> <sitemapnode url = "~ One/cone/B. aspx "Title =" one sub-directory B "Description =" "/> </sitemapnode> <sitemapnode url =" "Title =" Two directory "descripition =" here is the introduction"> <sitemapnode url = "~ /Two/a. aspx "Title =" Two directory subdirectory a "descripition =" here is the introduction "/> <sitemapnode url = "~ /Two/B. aspx "Title =" Two directory subdirectory B "descripition =" "/> </sitemapnode> <! -- <Sitemapnode sitemapfile = "~ /Mysm. sitemap "/> --> <! -- <Sitemapnode provider = "sqlsitemap"/> --> <sitemapnode url = "sitemap. aspx "Title =" Dynamic Modification content "Description =" Dynamic Modification of site maps in memory "/> </sitemapnode> </sitemap>
Then we add a Treeview control on the default. aspx page and configure its data source as a site map. As shown in the following figure:
Front-end code:
Protected void page_load (Object sender, eventargs e) {// register an event here, that is, this event (delegate) sitemap is triggered when the currentnode attribute is accessed. sitemapresolve + = new handler (sitemap_sitemapresolve);} sitemapnode handler (Object sender, sitemapresolveeventargs e) {// our custom processing method sitemapnode currentnode = sitemap. currentnode. clone (true); // obtain and create a copy of the current node, and copy its parent node sitemapnode tempnode = currentnod E; int id = NID (); int page = npage (); // obtain the variable if (ID> 0) {tempnode from the following method. url = tempnode. URL + "? Id = "+ id. tostring ();} If (ID> 0 & page> = 0) {tempnode. url = tempnode. url + "? Id = "+ id. tostring ();} else if (page> = 0) {tempnode. url = tempnode. url + "? Page "+ Page. tostring () ;}return tempnode;} private int NID () {// The number of randomly set return 12;} private int npage () {return 3 ;}}
Display Effect:
We only need to click the corresponding connection to return to the corresponding page.