A grid control for editing databases on the web. It is written for ASP with
lines of code, you will, with this control, be able to edit your data.
- Write protect fields you don't want the user to edit.
- ID fields can look up values in other recordsets.
- Sort by any column that supports sorting.
- Paging with custom page size.
- Automatically detects primary key, but can also be manually overridden.
- Get default values for new records with custom select statement.
To use the grid you create it by calling
new BGrid(rs) from
which also works from VBScript. The parameter in both methods is the recordset
you want the grid to display. This recordset should allow moving both back and
forward, so I usually set
on my connection.
I'm too lazy to manually declare all those ad-constants, so at the top of
config.asa I add the following. This means that all ADO constants are available,
and is required for the demo to work without a lot of work.
A simple example
Using the grid requires only a few lines of code:
var Conn = CreateConnection(); // CreateConnection is defined in misc.asp
var rs = Server.CreateObject("ADODB.Recordset");
var Grid = new BGrid(rs);
Grid.Process(); // Process must be called to handle saving and such stuff
Grid.Display(); // Display does just that
Grid = null;
rs = null;
Conn = null;
Since the EmployeeTerritories table has a field called TerritoryID which is
a foreign key to the Territories table, we can tell the grid to look for a
value to display from this table instead of displaying an ID that means
var rsTerritories = Conn.Execute("Territories");
When a record is being edited it will look similar to this picture:
Some of these are explained above, but there are a few I haven't mentioned yet:
option can be one of the following: "debug", "pagesize", "pk", "truncate".
value varies depending on the option. "debug" requires a boolean, "pagesize"
requires a number, "pk" is a comma separated list of fields which is the manually overridden
primary key, and "truncate" needs a number to know how many characters that should be
displayed of every field in the grid. Some examples:
field is the name of the field in the recordset, and sql
is the sql-statement used to find the default value for new records in this grid.
Grid.SetDefault("UserID","select max(UserID)+1 from TheTable");
Protects the fields in the fieldlist from editing. Example:
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.