当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET 2.0 - Navigation 导航
ASP.NET 2.0 has built-in navigation controls
在ASP.NET2.0中内置了导航控件
Maintaining the menu of a large web site is difficult and time consuming.
要为大型网站维护菜单是件非常困难和浪费时间的事
In ASP.NET 2.0 the menu can be stored in a file to make it easier to maintain. This file is normally called web.sitemap, and is stored in the root directory of the web.
在ASP.NET 2.0 中可以将菜单全部保存在一个文件中,这样会让维护更加的容易。这个文件通常被叫做 web.sitemap [网站地图] 这个文件通常保存在网站的根目录下。
In addition, ASP.NET 2.0 has three new navigation controls:
另外,ASP.NET 2.0 还有三个新的导航控件:
The following sitemap file is used in this tutorial:
在这个教程中将使用下面的网站地图文件:
<?xml version="1.0" encoding="ISO-8859-1" ?> |
Rules for creating a sitemap file:
建立网站地图文件有以下需要遵循的规则:
Note: The sitemap file must be placed in the root directory of the web and the URL attributes must be relative to the root directory.
注意:网站地图文件必须放在WEB的根目录下,而且URL属性必须关联到根目录地址
The <asp:Menu> control displays a standard site navigation menu.
<asp:Menu> 控加显示标准的导航菜单
Code Example:
代码举例:
<asp:SiteMapDataSource id="nav1" runat="server" /> <form runat="server"> |
The <asp:Menu> control in the example above is a placeholder for a server created navigation menu.
在上面举例中的 <asp:Menu> 控件为服务器建立导航菜单所保留的占位符。
The data source of the control is defined by the DataSourceId attribute. The id="nav1" connects it to the <asp:SiteMapDataSource> control.
通过使用 DataSourceId 属性来为控件的数据来源做定义。 id="nav1" 就将它跟 <asp:SiteMapDataSource> 控件连接起来了。
The <asp:SiteMapDataSource> control automatically connects to the default sitemap file (web.sitemap).
<asp:SiteMapDataSource> 控件会自动的与默认的网站地图文件(web.sitemap)进行连接
Click here to see a demo of Menu, TreeView, and SiteMapPath[查看各种导航菜单效果]
The <asp:TreeView> control displays a multi level navigation menu.
<asp:TreeView> 控件可以显示多级的导航菜单
The menu looks like a tree with branches that can be opened or closed with + or - symbol.
菜单看上去是树状的,有可以开关的分支,开关部分由 + 或 - 来标记
Code Example:
代码举例:
<asp:SiteMapDataSource id="nav1" runat="server" /> <form runat="server"> |
The <asp:TreeView> control in the example above is a placeholder for a server created navigation menu.
<asp:TreeView> 这个控件可为服务器建立导航菜单提供占位符
The data source of the control is defined by the DataSourceId attribute. The id="nav1" connects it to the <asp:SiteMapDataSource> control.
The <asp:SiteMapDataSource> control automatically connects to the default sitemap file (web.sitemap).
Click here to see a demo of Menu, TreeView, and SiteMapPath
The SiteMapPath control displays the trail (navigation path) to the current page. The path acts as clickable links to previous pages.
网站地图路径控件可以显示来到当前页面的踪迹(路径导航)。路径担当可以回到前页的可点连接。
Unlike the TreeView and Menu control the SiteMapPath control does NOT use a SiteMapDataSource. The SiteMapPath control uses the web.sitemap file by default.
不同于树型菜单和菜单控件,网站地图控件不需要使用SiteMapDataSource[网站地图数据源]。SiteMapPath 默认会使用 web.sitemap文件
Tips: If the SiteMapPath displays incorrectly, most likely there is an URL error (typo) in the web.sitemap file.
技巧:如果网站地图路径显示不正确,大多数情况是因为在web.sitemap文件中的URL有错误(打字的时候)
Code Example:
代码举例
<form runat="server">
<asp:SiteMapPath runat="server" />
</form>
Click here to see a demo of Menu, TreeView, and SiteMapPath