ASP Content Linking 组件

实例

Content Linking 组件

本例会构建一个内容列表。

Content Linking 组件 2

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


ASP Content Linking 组件

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

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

语法
  1. <%
  2. Set nl=Server.CreateObject( "MSWC.NextLink" )
  3. %>

首先,我们会创建文本文件 - "links.txt"。此文件包含需要导航的页面的相关信息。页面的排列顺序应该与它们的显示顺序相同,并包含对每个文件的描述(使用制表符来分隔文件名和描述信息)。

提示:如果你希望向列表添加文件信息,或者改变在列表中的页面顺序,那么你需要做的所有事情仅仅是修改这个文本文件而已!然后导航系统会自动地更新!

"links.txt":

  1. asp_intro.asp ASP 简介
  2. asp_syntax.asp ASP 语法
  3. asp_variables.asp ASP 变量
  4. asp_procedures.asp ASP 程序

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

"nlcode.inc":

  1. <%
  2. 'Use the Content Linking Component
  3. 'to navigate between the pages listed
  4. 'in links.txt
  5. dim nl
  6. Set nl=Server.CreateObject("MSWC.NextLink")
  7. if (nl.GetListIndex("links.txt")>1) then
  8. Response.Write("<a href='" &amp; nl.GetPreviousURL("links.txt"))
  9. Response.Write("'>Previous Page</a>")
  10. end if
  11. Response.Write("<a href='" &amp; nl.GetNextURL("links.txt"))
  12. Response.Write("'>Next Page</a>")
  13. %>

ASP Content Linking 组件的方法

GetListCount 方法

返回内容链接列表文件中所列项目的数目:

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetListCount("links.txt")
  5. Response.Write("There are ")
  6. Response.Write(c)
  7. Response.Write(" items in the list")
  8. %>

输出:

  1. There are 4 items in the list
GetListIndex 方法

返回在内容链接列表文件中当前文件的索引号。第一个条目的索引号是 1。假如当前页面不在列表文件中,则返回 0。例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetListIndex("links.txt")
  5. Response.Write("Item number ")
  6. Response.Write(c)
  7. %>

输出:

  1. Item number 3
GetNextDescription 方法

返回在内容链接列表文件中所列的下一个条目的文本描述。假如在列表文件中没有找到当前文件,则列表中最后一个页面的文本描述。

例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetNextDescription("links.txt")
  5. Response.Write("Next ")
  6. Response.Write("description is: ")
  7. Response.Write(c)
  8. %>

输出:

  1. Next description is: ASP Variables
GetNextURL 方法

返回在内容链接列表文件中所列的下一个条目的 URL。假如在列表文件中没有找到当前文件,则列表中最后一个页面的 URL。例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetNextURL("links.txt")
  5. Response.Write("Next ")
  6. Response.Write("URL is: ")
  7. Response.Write(c)
  8. %>

输出:

  1. Next URL is: asp_variables.asp
GetNthDescription 方法

返在内容链接列表文件中所列的第 N 个页面的描述信息。例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetNthDescription("links.txt",3)
  5. Response.Write("Third ")
  6. Response.Write("description is: ")
  7. Response.Write(c)
  8. %>

输出:

  1. Third description is: ASP Variables
GetNthURL 方法

返在内容链接列表文件中所列的第 N 个页面的 URL。例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetNthURL("links.txt",3)
  5. Response.Write("Third ")
  6. Response.Write("URL is: ")
  7. Response.Write(c)
  8. %>

输出:

  1. Third URL is: asp_variables.asp
GetPreviousDescription 方法

返回在内容链接列表文件中所列前一个条目的文本描述。假如在列表文件中没有找到当前文件,则列表中第一个页面的文本描述。例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetPreviousDescription("links.txt")
  5. Response.Write("Previous ")
  6. Response.Write("description is: ")
  7. Response.Write(c)
  8. %>

输出:

  1. Previous description is: ASP Variables
GetPreviousURL 方法

返回在内容链接列表文件中所列前一个条目的 URL。假如在列表文件中没有找到当前文件,则列表中第一个页面的URL。例子

  1. <%
  2. dim nl,c
  3. Set nl=Server.CreateObject("MSWC.NextLink")
  4. c=nl.GetPreviousURL("links.txt")
  5. Response.Write("Previous ")
  6. Response.Write("URL is: ")
  7. Response.Write(c)
  8. %>

输出:

  1. Previous URL is: asp_variables.asp

分类导航