Creating a Datagrid Class in classic ASP

Analysis of the Class

O.k. first of you declare the class, private variables and code for when the class is first instantiated. As I said you must understand what is involved in making a class or you might be a bit confused:-

Class caDataGrid

  'private variables
  private pAutoColumns, pConnStr, pSqlStr, intColCnt
  Private pOutPut, pConn, pRec, x, y, pArray

  'this runs when you create a reference to the caDataGrid class
  Private Sub Class_Initialize()
      Set pConn = server.createobject("adodb.connection")
      Set pRec = server.createobject("adodb.recordset")
      intColCnt = 0
      pAutoColumns = True
  End Sub


When the Class initializes we set our connection object and recordset object as adodb objects. We also set the Column Count variable to 0 for use when we want to define our own columns and finally we default to AutoColumns=true. It's in this procedure you would put any defaults you want for your class.

Next we create the procedures that allow us to set the various proerties:-

  'Properties - all writable
  Public Property Let ConnectionString(strConn)
      pConnStr = strConn
  End Property

  Public Property Let AutoColumns(bAutoCols)
      If bAutoCols = True or bAutoCols = False then
          pAutoColumns = bAutoCols
      End IF
  End Property

  Public Property Let SqlString(strSql)
      pSqlStr = strSql
  End Property


I haven't included code for reading these values, 'Public Property Get', as we don't really need to do this. I'm skimping a bit on error checking but the procedure to set the AutoColumns boolean checks to make sure only true or false is passed to it, for example. Otherwise in this case it remains true from the initializing code. It's a good idea to include more complete error code for these procedures to ensure proper values are set and especially if you wanted to make your class widely available.

You might also like...

Comments

About the author

Brian O'Connell Ireland

Microsoft Certified Applications Developer with 10 years experience developing web based applications using asp, asp.net for a Local Authority in Dublin. Clings to a firm belief that a web appli...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”