SITEMAPDATASOURCE控件中,需要特别的建立一个web.sitemap的XML文件,该文件中存贮网站的结构,比如<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="default.aspx?id=-1" title="首页">
<siteMapNode url="default2.aspx?id=0" title="商品"/>
<siteMapNode url="default3.aspx?id=1" title="社区"/>
</siteMapNode>
</siteMap>之后,在default.aspx中,写入代码:<%@ Page Language="C#" %>
<script runat=server>
protected void Page_Load()
{
int index = -1;
Int32.TryParse(Request.QueryString["id"], out index);
Tabs.SelectedIndex = index;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style>
a
{
color: #000000;
text-decoration: none;
}
。myTab
{
background: #6666ff;
padding: 4px;
}
。myTabSelected
{
background: #ff00ff;
padding: 4px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<asp:DataList RepeatDirection=Horizontal ID="Tabs" runat="server" DataSourceID="SiteMapDataSource1">
<ItemTemplate>
<td width="4" height="20" valign="top" nowrap class="myTab">
<a href='<%# Eval("Url") %>'><%# Eval("Title") %></a>
</td>
</ItemTemplate>
<SelectedItemTemplate>
<td width="4" height="20" valign="top" nowrap class="myTabSelected">
<a href='<%# Eval("Url") %>'><%# Eval("Title") %></a>
</td>
</SelectedItemTemplate>
</asp:DataList>
</table>
<asp:SiteMapDataSource ShowStartingNode=false ID="SiteMapDataSource1" runat="server" />
</div>
</form>
</body>
</html>
就可以实现简单的页面导航的效果了