| ASP.NET 2.0站点地图搭建网站导航结构 |
|
 |
|
| 日期:2006-8-10 10:14:09 人气:
[大
中 小] |
|
|
三、 使用SiteMapPath控件
在详细讨论细节前,让我们首先创建我们需要的目录结构和Web表单。首先,把两个文件夹Products和Services添加到网站。然后,添加一个新的Master页面MasterPage.master。接着添加显示在表格2中的Web表单,并且确保当你添加它们时都为其设置master页面。
| Web表单名 |
文件夹 |
| Default.aspx |
Website root |
| Contact.aspx |
Website root |
| Default.aspx |
Products |
| Product1.aspx |
Products |
| Product2.aspx |
Products |
| Default.aspx |
Services |
| Service1.aspx |
Services |
| Service2.aspx |
Services | 表格2:Web表单列表
现在,打开你前面添加的Master页面。把一个Label控件和一个SiteMapPath控件拖动到它上面。然后,把该Label的Text属性设置为“Welcome!”。
下列的列表显示了MasterPage.master页面中的所有标记:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Font-Size="XX-Large" ForeColor="Blue" Text="Welcome!"></asp:Label><br /> <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em" PathSeparator=" : "> <PathSeparatorStyle Font-Bold="True" ForeColor="#5D7B9D" /> <CurrentNodeStyle ForeColor="#333333" /> <NodeStyle Font-Bold="True" ForeColor="#7C6F57" /> <RootNodeStyle Font-Bold="True" ForeColor="#5D7B9D" /> </asp:SiteMapPath> <br /> <br /> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder> </div> </form> </body> </html> | 现在,从根文件夹打开Default.aspx。Default.aspx应该看似图4的样子。
 图4:Default.aspx的示例运行
| 为了设计这个页面,添加一个具有4行和1列的表格。拖动一个Label控件到最上边一行并且设置它的Text属性为“欢迎来到我们的网站!”。然后,拖动三个HyperLink控件到剩下的行上,并且设置它们的Text和NavigateUrl属性,显示于表格3中。
| HyperLink ID |
Text属性 |
NavigateUrl属性 |
| HyperLink1 |
Products |
~/products/default.aspx |
| HyperLink2 |
Services |
~/Services/default.aspx |
| HyperLink3 |
Contact Us |
~/contact.aspx | 表格3:设置HyperLinks的属性
|
|
|
| 出处:本站原创 作者:zzcode |
|
|