View Single Post
Old January 16th, 2004, 01:48 AM
Glen Conaway Glen Conaway is offline
Registered User
Join Date: Jan 2004
Location: San Diego, CA, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Grant,
I'm just a newbe but I mannaged to get this one to work.

I don't know what you did wrong but I have pasted my code below, being that their is no sample code for this one in the code download.
I sure hope this helps!
I am having trouble with the next exercise DataGrid Updates, check out my post.

Imports System.Data
Imports System.Data.SqlClient

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents grdAuthors As System.Web.UI.WebControls.DataGrid

    ' Declare a connection object that is global in scope...
    Dim objConnection As SqlConnection

#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.
    End Sub

#End Region

    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

        ' Initialize the Connection object...
        objConnection = New SqlConnection("Server=New\NetSdk;database=pubs;Int egrated Security=sspi")

        ' Only bind the data the first time the page is built...
        ' Subsequent post backs will be to sort the data in the grid...
        If Not (IsPostBack) Then
            BindGrid("Last Name")

        End If

    End Sub

    Public Sub BindGrid(ByVal strSortField As String)
        ' Declare objects...
        Dim objDataSet As DataSet
        Dim objDataAdapter As SqlDataAdapter

        'Set the Sql String...
        objDataAdapter = New SqlDataAdapter( _
        "Select au_lname AS 'Last Name', au_fname AS 'First Name', " & _
        "Title AS 'Book Title', price AS 'Retail Price' " & _
        "From authors " & _
        "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
        "JOIN titles ON titleauthor.title_id = titles.title_id " & _
        "ORDER BY au_lname, au_fname", objConnection)

        ' Initialize the DataSet object and fill it...
        objDataSet = New DataSet()
        objDataAdapter.Fill(objDataSet, "Authors")

        ' Declare a DataView object, populate it,
        ' and sort the data in it...
        Dim objDataView As DataView = _
        objDataView.Sort = strSortField

        ' Bind the DataView object to the DataGrid control...
        grdAuthors.DataSource = objDataView

        ' Clean up...
    End Sub

    Private Sub grdAuthors_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles grdAuthors.SortCommand
        ' Bind the DataGrid using the sort column requested
    End Sub

    Private Sub grdAuthors_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grdAuthors.SelectedIndexChanged

    End Sub
End Class