Controls (4) -- The Treeview control uses the sitemapdatasource control as the data source to implement the simplest Site Map

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.