dd

ASP Content Linking 组件


在线实例

Content Linking 组件
本例构建一个内容列表。

<!DOCTYPE html>
<html>
<body>

<p>
The example below builds a table of contents.
</p>

<%
dim c
dim i
set nl=server.createobject("MSWC.Nextlink")
c = nl.GetListCount("text\links.txt")
i = 1
%>
<ul>
<%do while (i <= c) %>
<li><a href="<%=nl.GetNthURL("text\links.txt", i)%>">
<%=nl.GetNthDescription("text\links.txt", i)%></a>
<%
i = (i + 1)
loop
%>
</ul>
<p>
The text file contains a list of page urls
and link descriptions. It contains one line of text for each page. Note that the url and
description MUST be separated by the TAB character.
</p>
<p>
<a href="text/links.txt"><img src="/images/btn_view_text.gif"></a>
</p>
</body>
</html>

Content Linking 组件 2
本例使用 Content Linking 组件在一个文本文件所列的页面间进行导航。

<!DOCTYPE html>
<html>
<body>

<h1>
This is page 1!
</h1>

<%
Set nl=Server.CreateObject("MSWC.NextLink")
If (nl.GetListIndex("text/links2.txt")>1) Then
%>
<a href="<%Response.Write(nl.GetPreviousURL("text/links2.txt"))%>">Previous Page</a>
<%End If%>

<a href="<%Response.Write(nl.GetNextURL("text/links2.txt"))%>">Next Page</a>

<p>The example uses the Content Linking Component 
to navigate between the pages in a text file.</p>

<p>
<a href="text/links2.txt"><img src="/images/btn_view_text.gif"></a>
</p>
</body>
</html>

ASP Content Linking 组件

ASP Content Linking 组件用于创建快捷便利的导航系统!

Content Linking 组件会返回一个 Nextlink 对象,这个对象用于容纳需要导航网页的一个列表。

语法

<%
Set nl=Server.CreateObject("MSWC.NextLink")
%>

ASP Content Linking 实例

首先,我们会创建一个文本文件 - "links.txt":

asp_intro.asp ASP 简介
asp_syntax.asp ASP 语法
asp_variables.asp ASP 变量
asp_procedures.asp ASP 程序

上面的文本文件包含需要导航的页面。页面的排列顺序应该与它们的显示顺序相同,并包含对每个文件名的描述(使用制表符来分隔文件名和描述信息)。

注释:如果您希望向列表添加页面,或者改变在列表中的页面顺序,那么您需要做的仅仅是修改这个文本文件而已!导航会自动更新!

然后我们创建一个引用文件,"nlcode.inc"。.inc 文件创建一个 NextLink 对象来在 "links.txt" 中列出的页面间进行导航。

"nlcode.inc":

<%
dim nl
Set nl=Server.CreateObject("MSWC.NextLink")
if (nl.GetListIndex("links.txt")>1) then
Response.Write("<a href='" & nl.GetPreviousURL("links.txt"))
Response.Write("'>Previous Page</a>")
end if
Response.Write("<a href='" & nl.GetNextURL("links.txt"))
Response.Write("'>Next Page</a>")
%>

请在文本文件 "links.txt" 列出的每个 .asp 页面中放置一行代码:<!-- #include file="nlcode.inc"-->。这行代码会在 "links.txt" 中列出每个页面上引用 "nlcode.inc" 中的代码,这样导航就可以工作了。

ASP Content Linking 组件的方法

方法描述实例
GetListCount返回内容链接列表文件中所列项目的数量。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetListCount("links.txt")
Response.Write("There are ")
Response.Write(c)
Response.Write(" items in the list")
%>

输出:

There are 4 items in the list

GetListIndex返回在内容链接列表文件中当前条目的索引号。第一个条目的索引号是 1。如果当前页面不在内容链接列表文件中,则返回 0。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetListIndex("links.txt")
Response.Write("Item number ")
Response.Write(c)
%>

输出:

Item number 3

GetNextDescription返回在内容链接列表文件中所列的下一个条目的文本描述。如果在列表文件中没有找到当前文件,则返回列表中最后一个页面的文本描述。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNextDescription("links.txt")
Response.Write("Next ")
Response.Write("description is: ")
Response.Write(c)
%>

输出:

Next description is: ASP Variables

GetNextURL返回在内容链接列表文件中所列的下一个条目的 URL。如果在列表文件中没有找到当前文件,则返回列表中最后一个页面的 URL。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNextURL("links.txt")
Response.Write("Next ")
Response.Write("URL is: ")
Response.Write(c)
%>

输出:

Next URL is: asp_variables.asp

GetNthDescription返在内容链接列表文件中所列的第 N 个页面的描述信息。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNthDescription("links.txt",3)
Response.Write("Third ")
Response.Write("description is: ")
Response.Write(c)
%>

输出:

Third description is: ASP Variables

GetNthURL返回在内容链接列表文件中所列的第 N 个页面的 URL。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetNthURL("links.txt",3)
Response.Write("Third ")
Response.Write("URL is: ")
Response.Write(c)
%>

输出:

Third URL is: asp_variables.asp

GetPreviousDescription返回在内容链接列表文件中所列的前一个条目的文本描述。如果在列表文件中没有找到当前文件,则返回列表中第一个页面的文本描述。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetPreviousDescription("links.txt")
Response.Write("Previous ")
Response.Write("description is: ")
Response.Write(c)
%>

输出:

Previous description is: ASP Variables

GetPreviousURL返回在内容链接列表文件中所列的前一个条目的 URL。如果在列表文件中没有找到当前文件,则返回列表中第一个页面的 URL。<%
dim nl,c
Set nl=Server.CreateObject("MSWC.NextLink")
c=nl.GetPreviousURL("links.txt")
Response.Write("Previous ")
Response.Write("URL is: ")
Response.Write(c)
%>

输出:

Previous URL is: asp_variables.asp