Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write ASP.NET site navigation

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to write ASP.NET site navigation". In daily operation, I believe many people have doubts about how to write ASP.NET site navigation. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "how to write ASP.NET site navigation". Next, please follow the editor to study!

Navigation actually provides visitors with something similar to a map, allowing visitors to find what they want more quickly.

An important concept introduced in 2. 0 is that the site map siteMap is a XML file, but its suffix is not XML.

To create a consistent and manageable navigation solution for your site, you can use asp.net site navigation. Asp.net site navigation provides the following functions:

After learning some basics, let's do a simple example of navigation.

1. First create a master

Html Code:

Your current location is: all rights reserved.

The effect displayed is:

2. Establish the following navigation structure (uniformly apply the master above)

3. Add a site map (the name cannot be changed)

The code under Web.sitemap is as follows:

4. A.aspx in the root directory and 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, we will talk about dynamically modifying the site map in memory. What does it mean to dynamically modify the site map in memory?

For example, there are usually many articles in the list of articles, and we can't put them all in the site map, not to mention that the article ID, column number, commodity classification or commodity ID are not what we can expect in advance, so if there is no in the site map, it cannot be displayed on the outside, what should we do? This requires dynamic modification of the in-memory site map.

As for the questions raised above, we assume that there is an article management system with the following structure:

Home page-News-International News (list)

You can assume that the international news page is list.aspx, and different columns will have different ID. Then the address structure is assumed to be as follows:

Xxx.com--~/news/--list.aspx?id=3&page=12

With such a structure, we can only statically write url= "~ / news/list.aspx" in the site map when we deal with the news list page. So if the above structure appears while others are browsing, we will deal with it next.

Web.sitemap:

Title is mainly used to dynamically modify the memory of this sentence to demonstrate.

Then put a SitemapPath control in the demo page sitemap.aspx, and pay attention to setting its renderCurrentNodeAsLink to true (indicating that the current node is a link)

The background code of the page:

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 SiteMap.SiteMapResolve+=new SiteMapResolveEventHandler (SiteMap_SiteMapResolve) is triggered when the CurrentNode property is accessed. } SiteMapNode SiteMap_SiteMapResolve (object sender,SiteMapResolveEventArgs e) {/ / our custom processing method gets and creates a copy of the current node and copies its 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.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 } / / set a random number. Private int nid () {return 3;} private int npage () {return 12;}

Explanation: the above nid () and npage () are two methods used to obtain parameters, which actually depend on the actual situation.

To run, let's look at the properties of this link:

At this point, we have simply implemented the dynamic modification of the site map in memory!

At this point, the study on "how to write ASP.NET site navigation" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report