Protected Sub gvONe_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles gvOne.DataBound
Dim valueInStock As Decimal = 0
'the rows collection includes rows only on the current page
'not 'virtual' rows
For Each row As GridViewRow In gvOne.Rows
Dim price As Decimal = Decimal.Parse(row.Cells(2).Text)
Dim unitsInStock As Integer = Integer.Parse(row.Cells(3).Text)
valueInStock += price * unitsInStock
Next
'update the footer
Dim footer As GridViewRow = gvOne.FooterRow
'set teh first cell to span over the entire row
footer.Cells(0).ColumnSpan = 3
footer.Cells(0).HorizontalAlign = HorizontalAlign.Center
'remove the unneeded cells
footer.Cells.RemoveAt(2)
footer.Cells.RemoveAt(1)
'add the text
footer.Cells(0).Text = "Total value in stock (on this page): " & valueInStock.ToString("C")
End Sub
Partial Class ItemRemovedCallback
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Me.IsPostBack) Then
lblInfo.Text &= "Creating items...
"
Dim itemA As String = "item A"
Dim itemB As String = "item B"
Cache.Insert("itemA", itemA, Nothing, DateTime.Now.AddMinutes(60), TimeSpan.Zero, CacheItemPriority.Default, AddressOf ItemRemovedCallback)
Cache.Insert("itemB", itemB, Nothing, DateTime.Now.AddMinutes(60), TimeSpan.Zero, CacheItemPriority.Default, AddressOf ItemRemovedCallback)
End If
End Sub
Protected Sub cmdCheck_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCheck.Click
Dim itemList As String = String.Empty
For Each item As DictionaryEntry In Cache
itemList &= item.Key.ToString() & " "
Next item
lblInfo.Text &= "
Found: " & itemList & "
"
End Sub
Protected Sub cmdRemove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
lblInfo.Text &= "
Removing itemA.
"
Cache.Remove("itemA")
End Sub
Private Sub ItemRemovedCallback(ByVal key As String, ByVal value As Object, ByVal reason As CacheItemRemovedReason)
'this fires after the request has ended when the item is removed.
'if either item has been removed, make sure the othe ritem is also removed
If key = "itemA" OrElse key = "itemB" Then
Cache.Remove("itemA")
Cache.Remove("itemB")
End If
End Sub
End Class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment