Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Imports APNSoft.WebControls

Partial Public Class DataGrid_CustomAJAXCall
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        'Apply event-handling method
        AddHandler myDataGrid.CallTheServer, AddressOf myDataGrid_CallTheServer

        'Define SQL query
        Dim SqlQuery As String = "SELECT '0' as LineNumbers, ISBN, Title, Synopsis FROM Books"

        'Get DataTable (MS Access Database)
        Dim myDataSource As DataTable = DataBase.GetDataTableOleDb(SqlQuery, "~/DataGrid/DataBases/Books.mdb")

        'Set the data source
        myDataGrid.KeyFieldName = "ISBN"
        myDataGrid.DataSource = myDataSource

        'Format Columns
        myDataGrid.Columns("LineNumbers").LineNumbers = True
        myDataGrid.Columns("LineNumbers").FormatType = GetType(System.String)
        myDataGrid.Columns("LineNumbers").FormatString = "{0}."
        myDataGrid.Columns("LineNumbers").CssClass = "LineNumbers"
        myDataGrid.Columns("LineNumbers").Width = 40
        myDataGrid.Columns("LineNumbers").Sortable = False
        myDataGrid.Columns("LineNumbers").Resizable = False
        myDataGrid.Columns("LineNumbers").HeaderText = ""

        myDataGrid.Columns("ISBN").Visible = False
        myDataGrid.Columns("Title").Width = 410
        myDataGrid.Columns("Title").HeaderText = "Book title:"
        myDataGrid.Columns("Synopsis").Visible = False
    End Sub

    'Server-side procedure for the CallTheServer event
    Private Sub myDataGrid_CallTheServer(ByVal sender As Object, ByVal e As DataGridEventArgs)
        'Get Row Data
        Dim myGridRow As GridRow = e.GridRow

        'Get book details
        Dim BookDetails As String = ""
        BookDetails &= "<img src='" & _
            "./Images/Books/" & _
            myGridRow.Cells("ISBN").Value.ToString() & ".gif" & _
            "' align='left' vspace='4' style='padding-right:16px;padding-bottom:70px;'/>"
        BookDetails &= "<small>" & _
            myGridRow.Cells("Synopsis").Value.ToString() & "</small>"

        BookDetails = BookDetails.Replace(vbCrLf, "<br/>")

        'Set book details as parameter
        e.Parameter = BookDetails
    End Sub

End Class