在asp.net 2.0中提供了两种导航控件
- TreeView控件
- 可扩展和折叠的分支
- 节点是可导航, 可选择的,也可添加选择框
- TreeNode对象定义的内容
- TreeNodes可以通过声明方式,写代码方式或通过数据邦定方式添加
- TreeNodes可以按需装载
- Menu控件
- 在Web页面中提供下拉或弹出式的菜单
- Items 是导航的或可选择的
- Menu 控件显示可以是竖直方向也可以是水平方向
- MenuItems可以通过声明方式,写代码方式或通过数据邦定方式添加
同时提供了一个用于连接数据源的控件SiteMapDataSource,TreeView控件和Menu控件可以利用它实现自身于数据源的绑定。SiteMapDataSource它是通过数据邦定方式添加同时提供了一个用于连接数据源的控件SiteMapDataSource,TreeView控件和Menu控件可以利用它实现自身于数据源的绑定。SiteMapDataSource会查找项目中名为web.sitemap的 一个XML文件,如果想使用web.sitemap为名字,可以在配置文件web.config中改名。下面的Acme.sitemap就时更名后的新名字。
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
该XML文件中定义了关于导航的所有信息,以下是一个web.sitemap的例子。
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
其中有一个根节点siteMap,然后下面是子节点,子节点有两个属性一个是显示的文本,一个是要导航到的URL,子节点可以镶套。SiteMapDataSource控件有ShowStartingNode属性,通过设置它可以可以决定是否显示根节点的第一个子节点,也就是上面代码中Text为“Home”的节点,同时可以通过StartingNodeUrl来设置其导航到的页面。
如果要将TreeView于Menu绑定到SiteMapDataSource只需按以下方式定义,其中SiteMap为SiteMapDataSource的 ID名
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
此外,可以通过在web.sitemap中进行设置,可以控制权限,这样就能仅通过一个XML文件,让具有不同权限的人看到不同的菜单。要设置权限只要在web.sitemap中的子节点加上一个roles属性,然后在web.config文件中将securityTrimmingEnabled设置为True就可以了。下面是例子。
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/dot.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)