Listing H
Public Class ViewBooks
    Inherits System.Web.UI.Page
    Protected WithEventsbtnEdit As System.Web.UI.WebControls.Button
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
 
 
#Region " Web Form Designer Generated Code "
 
 
    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 
 
    End Sub
 
 
    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
       InitializeComponent()
    End Sub
 
 
#End Region
 
 
    Private m_BookId As String
 
 
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
 
 
        If Not Me.IsPostBack Then
           BindDataGrid()
        End If
 
 
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' As items as bound to the grid, we set the items onclick method to perform the same action that the hidden link
    ' button would perform
    '#########################################################################################################################
    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        Dim itemType As ListItemType = e.Item.ItemType
        If ((itemType = ListItemType.Pager) Or _
           (itemType = ListItemType.Header) Or _
           (itemType = ListItemType.Footer)) Then
            Return
        Else
            Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
           e.Item.Attributes("onclick") = Page.GetPostBackClientHyperlink(button, "")
        End If
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' As the items are created in our datagrid, we bind an onmouseover event to switch the row's cursor style to a hand
    '#########################################################################################################################
    Private Sub DataGrid1_ItemCreated(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemCreated
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.SelectedItem Then
           e.Item.Attributes.Add("onmouseover", "this.style.cursor='hand'")
        End If
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' When a row is clicked and selected, we provide an "Edit" button
    '#########################################################################################################################
    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
        If Not Me.DataGrid1.SelectedItem Is Nothing Then
           Me.btnEdit.Visible = True
        Else
           Me.btnEdit.Visible = False
        End If
 
 
    End Sub
 
 
    Private Sub BindDataGrid()
        Dim BizObj As New BookServices()
        Me.DataGrid1.DataSource = BizObj.GetBooks(Nothing, Nothing, Nothing, Nothing)
       Me.DataBind()
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' When the edit button is clicked we extract the Id of the book and transfer execute to the edit book page
    ' The Id of the book is placed in a property of this page allowing the EditBook.aspx page to extract the property
    ' from the request context
    '#########################################################################################################################
    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim SelectedItem As DataGridItem = Me.DataGrid1.SelectedItem
        Dim Id As String = SelectedItem.Cells(1).Text
 
 
       BookId = Id
       Server.Transfer(WebPageNames.EDIT_BOOK)
    End Sub
 
 
 
 
    '#########################################################################################################################
    ' Public property to allow other pages to access the BookId
    '#########################################################################################################################
    Public Property BookId() As String
        Get
            Return Me.m_BookId
        End Get
        Set(ByVal Value As String)
           Me.m_BookId = Value
        End Set
    End Property
End Class