Real-Time Data Grid Part 1/2 - Project Overview (Page 2 of 5 )
In this article we will be creating a fully dynamic client-side data grid from scratch. This data grid will display a set number of records from a table (which we can specify). These records can be updated and deleted on the fly, without the page having to refresh. Before we get into the actual code, take a look at the diagram below to understand how our control will work:
As you may or may not know, ASP includes support for basic class creation and instantiation. Classes in ASP can include both public and private methods and members. Here's the code for a simple person class in ASP:
Public Property Get Name()
Name = m_PersonName
Public Property Let Name(theName)
m_PersonName = theName
Public Function DoSomething()
‘VBScript code for function goes here
The person class example above contains one private member (the persons name), two public properties (which get and set the persons name), and one public function. To use this class in our ASP pages, we could do something like this:
Set person1 = new Person
person1.Name = "Fred Smith"
Response.Write "Persons name is " & person1.name
This is a very powerful feature of ASP, and I bet that half of you reading this article didn't even know that you could create custom classes in ASP. Now that we understand the basics of creating and instantiating classes in ASP, let's start looking at the DynamicGrid class that we are going to build.
In this article I won't describe all of the code for the entire DynamicGrid class, but rather concentrate on the functionality of the class and how to use it. The complete class is available for download here, or under the "Support Material" section at the end of this article. You should download the code and have it open so that you can reference it throughout the rest of this article.
Our DynamicGrid class contains three private members, four public properties, two sub-routines, and one function. The details of these are shown below:
m_TableName: Used to hold the name of the table that we will be loading and modifying records for.
m_RowsPerPage: Used to hold the number of rows to return from the table in our SQL Server 2000 database.
m_Initialized: Before our grid can be displayed, its InitializeGrid function must be called. When it is called, the value of m_Initialized is set to true.
Get TableName: Returns the value of the m_TableName variable
Let TableName: Allows the value of the m_TableName variable to be set
Get RowsPerPage: Returns the value of the m_RowsPerPage variable
Let RowsPerPage: Allows the value of the m_RowsPerPage variable to be set
InitializeGrid: Makes sure the m_TableName variable contains a value, and also sets the value of the m_RowsPerPage variable to 10 if no value was specified for it.
GetConnection: Returns an ADO Connection object whose open method has been used to connect to our SQL Server 2000 database.
Let's now take a look at each of these functions in-depth.