在asp.net 2.0中,没有专门的页面导航控件,但可以使用sitemapdatasource配和datalist来实现。
sitemapdatasource控件中,需要特别的建立一个web.sitemap的xml文件,该文件中存贮网站的结构,
比如
<?xml version="1.0" encoding="utf-8" ?>
<sitemap xmlns="http://schemas.microsoft.com/as.net/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>
就可以实现简单的页面导航的效果了
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器