Home arrow ASP arrow Page 2 - Real-Time Data Grid Part 1/2
ASP

Real-Time Data Grid Part 1/2


In part one of this two-part article Annette, show us how to create an ASP class that allows us to work with our databases through a web browser. It will allow us to update and delete records dynamically using JavaScript and XMLHTTP, without ever having to refresh the page.

Author Info:
By: Annette Tennison
Rating: 4 stars4 stars4 stars4 stars4 stars / 16
February 07, 2002
TABLE OF CONTENTS:
  1. · Real-Time Data Grid Part 1/2
  2. · Project Overview
  3. · The GetConnection function
  4. · The InitializeGrid routine
  5. · Conclusion

print this article
SEARCH DEVARTICLES

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:

Steps to creating our project

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:

Class Person

Private m_PersonName

Public Property Get Name()

Name = m_PersonName

End Property

Public Property Let Name(theName)

m_PersonName = theName

End Property

Public Function DoSomething()

‘VBScript code for function goes here

End Function

End Class


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:

Dim person1

Set person1 = new Person

person1.Name = "Fred Smith"

Response.Write "Persons name is " & person1.name

person1.DoSomething()


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:

Members:
  • 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.
Properties:
  • 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
Sub-Routines:
  • 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.
  • DisplayGrid: Connects to database, retrieves m_RowsPerPage number of rows from the table named m_TableName. Loops through the record set and displays the results as HTML tables. Also outputs JavaScript functionality to update/delete the records dynamically using XMLHTTP.
Functions:
  • 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.
blog comments powered by Disqus
ASP ARTICLES

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials