当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET 2.0 - Navigation 导航

ASP.NET
ASP.NET 2.0 - Navigation 导航
C#中new和override区别
ASP.NET中 Bin,App_Browser,App_code,App_Data,App_Theme 等文件

ASP.NET 2.0 - Navigation 导航


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 850 ::
收藏到网摘: n/a

ASP.NET 2.0 has built-in navigation controls
在ASP.NET2.0中内置了导航控件


Web Site Navigation
网站导航

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 还有三个新的导航控件:

  • Dynamic menus
    动态菜单
  • TreeViews
    树型
  • Site Map Path
    网站地图路径

The Sitemap File
网站地图文件

The following sitemap file is used in this tutorial:
在这个教程中将使用下面的网站地图文件:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<siteMap>
<siteMapNode title="Home" url="/aspnet/w3home.aspx">
<siteMapNode title="Services" url="/aspnet/w3services.aspx">
<siteMapNode title="Training" url="/aspnet/w3training.aspx"/>
<siteMapNode title="Support" url="/aspnet/w3support.aspx"/>
</siteMapNode>
</siteMapNode>
</siteMap>

Rules for creating a sitemap file:
建立网站地图文件有以下需要遵循的规则:

  • The XML file must contain a <siteMap> tag surrounding the content
    其为XML文件,里面必须将内容放置在 <siteMap> 标签内
  • The <siteMap> tag can only have one <siteMapNode> child node (the "home" page)
    在<siteMap> 标签中只可以有一个 <siteMapNode> 子节点(首页)
  • Each <siteMapNode> can have several child nodes (web pages)
    每个<siteMapNode> 可以有多个子节点 (页面)
  • Each <siteMapNode> has attributes defining page title and URL
    每个<siteMapNode> 得有定义页面标题以及URL的属性

 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属性必须关联到根目录地址


Dynamic Menu
动态菜单

The <asp:Menu> control displays a standard site navigation menu.
<asp:Menu> 控加显示标准的导航菜单

Code Example:
代码举例:

<asp:SiteMapDataSource id="nav1" runat="server" />
<form runat="server">
<asp:Menu runat="server" DataSourceId="nav1" />
</form>

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[查看各种导航菜单效果]


TreeView
树形导航菜单

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">
<asp:TreeView runat="server" DataSourceId="nav1" />
</form>

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


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

评论 (1) 1 All

登陆 | 还没注册?