⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cart.aspx

📁 asp入门到精通的源代码
💻 ASPX
字号:
<%@ Page Language="VB" debug="true" %>
<HTML>
<HEAD>
    <SCRIPT RUNAT="SERVER">
    'called when the page loads
    sub Page_Load(obj as object, e as eventargs)
       'declare variables
       dim i, row as integer
       dim intCount as integer = Session.Count
       
       row = 0
       
       'if there are items in the session state, add headers to the table
       ' columns
       'table contains 2 columns, "Items" and "Quantity"
       if intCount > 0 then
          'create new table rows and cells
          dim r as HTMLTableRow = new HTMLTableRow
          dim objCell as HTMLTableCell = new HTMLTableCell
          
          'add a literalControl to hold text
          objCell.Controls.Add(new LiteralControl("<b>Items</b>"))
          'assign properties and add cell to row
          objCell.Width="250"
          r.Cells.Add(objCell)
          
          'repeat
          objCell = new HTMLTableCell
          objCell.Width="50"
          objCell.Controls.Add(new LiteralControl("<b>Quantity</b>"))
          r.Cells.Add(objCell)
          
          'add row to table
          Cart.Rows.Add(r)
       end if
       'loop through items in session state
       for i = 0 to intCount-1
          dim r as HTMLTableRow = new HTMLTableRow
          
          'alternate table row colors
          if row mod 2 then
             r.BGColor = "#CCCCCC"
          end if
          row = row + 1
          
          dim objCell as HTMLTableCell = new HTMLTableCell
          
          objCell.Controls.Add(new LiteralControl(Session.Keys(i)))
          r.Cells.Add(objCell)
          
          'add text input box to cell
          objCell = new HTMLTableCell
          dim objText = new HTMLInputText
          objText.ID = "Cell" & i
          objText.Value = Session.Item(i)
          objText.Size = 2
          objText.MaxLength = 2
          objCell.Controls.Add(objText)
          r.Cells.Add(objCell)
          
          Cart.Rows.Add(r)
          
       next
       
    end sub
    
    sub UpdateList(obj as object, e as eventargs)
       'this method updates values in session state
       dim objControl as HTMLInputText
       
       for i = 0 to Session.Count - 1
          'must obtain an object context
          objControl = FindControl("Cell" & i)
          if Cint(objControl.Value) = 0 then
             'Session(i).Remove
             Session(i) = ""
          else
             Session(i) = objControl.Value
          end if
       next
       
    end sub
    </SCRIPT>
 </HEAD>
 <BODY bgcolor="#FFFFFF">
 <font size="5">Sam's Teach Yourself ASP.NET in 21 Days: Day 5
                                         </font><hr><p>

 <form runat="server">
 <table cellpadding="2" cellspacing="2" border="1" id="Cart" runat="server"/><p>
 
 <input type="Button" value="Update Values" id="Update" onserverclick="UpdateList"
                                 runat="server"/>
 
 </form>
 <a href="browse.aspx">Continue Shopping</a>
       
 </BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -