Friday, October 7, 2011

October 7th 2011 Friday

Partial Class ServerControls
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim table1 As New HtmlTable()
'set the table's formatting-related properties
table1.Border = 1
table1.CellPadding = 3
table1.CellSpacing = 3
table1.BorderColor = "red"

'start adding content to the table
Dim row As HtmlTableRow
Dim cell As HtmlTableCell
For i As Integer = 1 To 5
'create a new row, and set its background color.
row = New HtmlTableRow()
If i Mod 2 = 0 Then
row.BgColor = ("lightyellow")
Else
row.BgColor = ("lightcyan")
End If

For j As Integer = 1 To 4
'create a cell and set its text
cell = New HtmlTableCell()
cell.InnerHtml = "Row: " & i.ToString() & "
Cell: " & j.ToString()

'add the cell to the current row
row.Cells.Add(cell)
Next j
'add teh rows to the table
table1.Rows.Add(row)
Next i
'add the table to the apge.
Me.Controls.Add(table1)
End Sub
End Class


Partial Class ServerSideEvents
Inherits System.Web.UI.Page


Protected Sub Ctrl_ServerChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles Textbox1.ServerChange
Response.Write("
  • SeverChange detected for " & (CType(sender, Control)).ID & "
  • ")
    End Sub

    Public Sub List1_ServerChanage(ByVal sender As Object, ByVal e As System.EventArgs) Handles List1.ServerChange
    Response.Write("
  • ServerChange detected for List1." & " The selected items are:

  • ")
    For Each li As ListItem In List1.Items
    If li.Selected Then
    Response.Write(" - " & li.Value & "
    ")
    End If
    Next
    End Sub

    Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.ServerClick
    Response.Write("
  • ServerClick ddetected for Submit1.
  • ")
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If (Not Page.IsPostBack) Then
    List1.Items.Add("Option 3")
    List1.Items.Add("Option 4")
    List1.Items.Add("Option 5")
    End If
    End Sub
    End Class


    Imports System
    Imports System.Linq
    Imports System.Diagnostics

    Namespace Apress.VisualBasicRecipes.Chapter06
    Public Class Recipe06_13
    'this field holds the size of our pages.
    Private Shared pageSize As Integer = 10
    Private Const Five_MB = 3 * (1024 * 1024)
    Public Shared Sub Main()
    'use LINQ to retrieve a List(Of Process) List of processes that are using more
    'than 5MB of memory. The ToList method is used to force the query to execute immediately
    'and save the results in the procs variable so they can be reused
    Dim procs = (From proc In Process.GetProcesses.ToList _
    Where proc.WorkingSet64 > Five_MB _
    Order By proc.ProcessName _
    Select proc).ToList

    Dim totalPages As Integer

    'determine the exact number of pages of information
    'available for display
    totalPages = Math.Floor(procs.Count / pageSize)
    If procs.Count Mod pageSize > 0 Then totalPages += 1

    Console.WriteLine("List of processes with memory usage over 5 MB:")
    Console.WriteLine("")

    'Loop and Display Each Page of Data
    For i = 0 To totalPages - 1
    Console.WriteLine("PAGE {0} OF {1}", i + 1.ToString(), totalPages.ToString())
    'query the procs collection and return a single page
    'of proceses using the Skip and Take clauses.
    Dim currentPage = From proc In procs _
    Skip i * pageSize Take pageSize

    'loop through all the process records for the current page
    For Each proc In currentPage
    Console.WriteLine("{0,-20} - {1,5} MB", proc.ProcessName, (proc.WorkingSet64 / (1024 * 1024)).ToString("#.00"))
    Next
    'check whether there are any more pages.
    If Not i = totalPages - 1 Then
    Console.WriteLine("Press Enter for the next page.")
    Console.ReadLine()
    End If
    Next
    Console.WriteLine("No more data available. Press Enter to end.")
    Console.ReadLine()



    End Sub
    End Class
    End Namespace

    No comments: