ASP Content Linking 组件


在线实例

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

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>
  6. The example below builds a table of contents.
  7. </p>
  8.  
  9. <%
  10. dim c
  11. dim i
  12. set nl=server.createobject("MSWC.Nextlink")
  13. = nl.GetListCount("text\links.txt")
  14. = 1
  15. %>
  16. <ul>
  17. <%do while (<= c) %>
  18. <li><a href="<%=nl.GetNthURL("text\links.txt", i)%>">
  19. <%=nl.GetNthDescription("text\links.txt", i)%></a>
  20. <%
  21. = (+ 1)
  22. loop
  23. %>
  24. </ul>
  25. <p>
  26. The text file contains a list of page urls
  27. and link descriptions. It contains one line of text for each page. Note that the url and
  28. description MUST be separated by the TAB character.
  29. </p>
  30. <p>
  31. <a href="text/links.txt"><img src="/images/btn_view_text.gif"></a>
  32. </p>
  33. </body>
  34. </html>

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

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>
  6. This is page 1!
  7. </h1>
  8.  
  9. <%
  10. Set nl=Server.CreateObject("MSWC.NextLink")
  11. If (nl.GetListIndex("text/links2.txt")>1) Then
  12. %>
  13. <a href="<%Response.Write(nl.GetPreviousURL("text/links2.txt"))%>">Previous Page</a>
  14. <%End If%>
  15.  
  16. <a href="<%Response.Write(nl.GetNextURL("text/links2.txt"))%>">Next Page</a>
  17.  
  18. <p>The example uses the Content Linking Component 
  19. to navigate between the pages in a text file.</p>
  20.  
  21. <p>
  22. <a href="text/links2.txt"><img src="/images/btn_view_text.gif"></a>
  23. </p>
  24. </body>
  25. </html>

ASP Content Linking 组件

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

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

语法

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

ASP Content Linking 实例

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

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

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

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

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

"nlcode.inc":

  1. <%
    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