從ASP遷移至ASP+ --轉換其他的頁面吧

- 中國WEB開發者網絡 (http://www.webasp.net)
-- 技術教程 (http://www.webasp.net/article/)
--- 從ASP遷移至ASP+ --轉換其他的頁面吧 (http://www.webasp.net/article/13/12580.htm)
-- 作者:未知
-- 發佈日期: 2004-08-25
原作者: 雨晨
至於剩餘的頁面,我們依樣畫葫蘆,使用ASP+ DataList或是Repeater控件。這樣做是必要的,因為按設計要求需要定制的數據佈局,而不是一個標準的表格顯示。其中有個頁面,classcatalog.aspx,有一處要求勾選值,然後根據選中的值,運行兩個可能輸出中的一個。該頁就利用了Repeater控件,因此我們顯示地創建了表格的行與列,而沒有讓控件來完成這一切。這是在templates的內部完成的。在ASP中,看起來是這樣子的:

   '檢查是否提供優惠

   If rsSessions("Special") = True Then

   '若本課程提供優惠,則輸出「Special Offer!」

   Response.Write "< td valign=top align=center>" & vbCrLf

   Response.Write "< a href=""classdetail.asp?SessionID="

   Response.Write rsSessions("SessionID")

   Response.Write """name=""Click for more detail"">"

   Response.Write "Special Offer!"

   Response.Write "< /td>"

   Else

   '若本課程不提供優惠,則在欄中輸出"--"

   Response.Write "< td valign=top align=center>--< /td>"

   End If

   為了在ASP+中達到同樣的效果,我們使用了一個函數。在腳本塊中,位於Page_Load 事件下,我們創建以下代碼:

   Function CheckSpecial(ByRef blnSpecial As Boolean, _

   ByRef intNumber As Integer) As String

   If blnSpecial = True Then

   CheckSpecial = "< a href=" & Chr(34) & _

   "classdetail.aspx?SessionID=" & _

   intNumber & Chr(34) & ">Special!!< /a>"

   Else

   CheckSpecial = "--"

   End If

   End Function

   然後只須從ASP+ Repeater中調用函數:

   < template name = "ItemTemplate">

   < tr>

   [ other data being displayed ]

   < td valign=top align=center>

   < %=CheckSpecial(Container.DataItem("Special"),

   Container.DataItem("Session_ID"))%>

   < /td>

   < /tr>

   < /template>

   Container指的是涉及我們的ASP+ Reapter控件的數據的父對象。通過調用Container.DataItem("Special")及Container.DataItem("Session_ID") ,將父對像(即ASP+ Repeater控件)中的列的值傳遞給了函數


webasp.net