今天自学导航页的内容,导航页的视频撸了好久才撸出来。开始觉得课程的讲师不求行。不多说了,直接上干货。
首先,新建一个sitemap后缀的站点地图页面,代码如下:`
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="~/上传下载文件.aspx" title="首页" description="">
<siteMapNode url="" title="硬件" description="" >
<siteMapNode url="~/SiteMaps/Map/Map.aspx" title="CPU" description=""/>
<siteMapNode url="~/SiteMaps/Map/Map1.aspx" title="显卡驱动" description=""/>
<siteMapNode url="~/SiteMaps/Map/Map2.aspx" title="声卡驱动" description=""/>
</siteMapNode>
<siteMapNode url="" title="软件" description="" />
<siteMapNode url="~/SiteMaps/Site/Site.aspx" title="QQ" description=""/>
<siteMapNode url="~/SiteMaps/Site/Site1.aspx" title="WeChat" description=""/>
<siteMapNode url="~/SiteMaps/Site/Site2.aspx" title="AliPay" description=""/>
</siteMapNode>
</siteMap>
写完之后,新建一个母版页SiteMap.Master,在母版页添加一个SiteMapPath控件,创建过程不再赘述,我直接把母版页的代码搬上来,如下:``
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="SiteMap.master.cs" Inherits="SiteMap" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
<!--导航控件SiteMapPath-->
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
然后新增一个web页面,新增的时候套用母版页。如图:
接下来是web页面的代码,如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/SiteMap.master" AutoEventWireup="true" CodeFile="Site1.aspx.cs" Inherits="SiteMaps_Site_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath>
</asp:Content>
效果图: