คอลเลกชันเนื้อหา ASP
❮ การอ้างอิงออบเจ็กต์แอปพลิเคชันที่สมบูรณ์
คอลเล็กชันเนื้อหาประกอบด้วยรายการทั้งหมดที่ต่อท้ายแอปพลิเคชัน/เซสชันผ่านคำสั่งสคริปต์
เคล็ดลับ:หากต้องการลบรายการออกจากคอลเล็กชันเนื้อหา ให้ใช้เมธอด Remove และ RemoveAll
ไวยากรณ์
Application.Contents(Key)
Session.Contents(Key)
Parameter | Description |
---|---|
key | Required. The name of the item to retrieve |
ตัวอย่างสำหรับ Application Object
ตัวอย่าง 1
ขอให้สังเกตว่าทั้งชื่อและ objtest จะถูกผนวกเข้ากับคอลเล็กชันเนื้อหา:
<%
Application("name")="W3Schools"
Set Application("objtest")=Server.CreateObject("ADODB.Connection")
%>
ตัวอย่าง 2
ในการวนรอบคอลเลคชันเนื้อหา:
<%
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br>")
next
%>
or:
<%
For i=1 to Application.Contents.Count
Response.Write(i & "=" & Application.Contents(i) & "<br>")
Next
%>
ตัวอย่างที่ 3
<%
Application("date")="2001/05/05"
Application("author")="W3Schools"
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x) & "<br>")
next
%>
Output:
date=2001/05/05
author=W3Schools
ตัวอย่างสำหรับ Session Object
ตัวอย่าง 1
ขอให้สังเกตว่าทั้งชื่อและ objtest จะถูกผนวกเข้ากับคอลเล็กชันเนื้อหา:
<%
Session("name")="Hege"
Set Session("objtest")=Server.CreateObject("ADODB.Connection")
%>
ตัวอย่าง 2
ในการวนรอบคอลเลคชันเนื้อหา:
<%
for each x in Session.Contents
Response.Write(x & "=" & Session.Contents(x) & "<br>")
next
%>
or:
<%
For i=1 to Session.Contents.Count
Response.Write(i & "=" & Session.Contents(i) & "<br>")
Next
%>
ตัวอย่างที่ 3
<%
Session("name")="Hege"
Session("date")="2001/05/05"
for each x in Session.Contents
Response.Write(x & "=" & Session.Contents(x) & "<br>")
next
%>
Output:
name=Hege
date=2001/05/05
❮ การอ้างอิงออบเจ็กต์แอปพลิเคชันที่สมบูรณ์