Consider an MS Access Database named 'GridTest'. To create an on-line
editable grid for the database, it must be specified in the System DSN
of the Server running iASP and a web server (e.g. Apache etc.).
The procedure is as follows:
- Open the Control Panel on the PC running Windows.
- Double-click the ODBC icon and then click System DSN.
NOTE: The System DSN stores information
about how to access databases. The System DSN is available to all users
of the computer while the User DSN is available only to the specific user,
and the File DSN can be shared by users who have the same database drivers
installed.
- Click the Add button and choose the Microsoft Access Driver.
- Click the Finish button.
- In the Data Source Name edit box, enter 'GridTest'.
- Click the Select button.
- Select the GridTest.mdb database.
- Click the OK button.
- Finally, click the OK button in the ODBC Data Source Administrator
dialog to finish data source configuration.
The 'GridTest' database has the following two tables:
Departments
Field Name |
Field Type |
ID |
AutoGenerated |
Phone |
Text |
Name |
Text |
Employees
Field Name |
Field Type |
ID |
AutoGenerated |
Department ID |
Number (Long) |
First Name |
Text |
Last Name |
Text |
Salary |
Currency |
Marital Status |
Number (Long) |
Fully Vested |
Number (Byte) |
NOTE: All the sample asp pages and the
GIF files included (i.e. edit.gif, delete.gif, add.gif, up.gif, down.gif,
forward.gif, backward.gif, cancel.gif, save.gif) must be copied to the
publishing directory of the Web Server being used. Otherwise the samples
will not function properly.
Sample code
<%
Set Grid = Server.CreateObject("Persits.AspGrid")
Grid.FileName = "Sample.asp"
Grid.Connect "sun.jdbc.odbc.JdbcOdbcDriver","jdbc:Odbc:GridTest", "",
""
Grid.SQL = "select id, name, phone from Departments"
Grid.Cols(1).Hidden = True
%>
<HTML>
<BODY>
<% Grid.Display %>
<% Grid.Disconnect %>
</BODY>
</HTML>
Sample code results
In the above Sample code the line Set Grid =Server.CreateObject("Persits.AspGrid")
simply creates an instance of the iASP_Grid object.
The line Grid.FileName = "Sample.asp" specifies the name of the file
in which the above script is saved. Here we have assumed the name
is Sample.asp. iASP_Grid will use this property to correctly generate
the ACTION attributes of all FORMs.
Grid.Connect "sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:Odbc:GridTest", "",
"" specifies the Jdbc-Odbc driver, a data source name (DSN), user id and
password. In this case the DSN is "GridTest". Assuming that
no security is used, the user id and password are left blank.
The line Grid.SQL = "select id, name, phone from Departments" specifies
the SQL SELECT statement that the grid is based on. It contains three
fields of the table although only two of them, name and phone are visible.
NOTE: There must be an IDENTITY column
(i.e. AutoNumber column or a PrimaryKey column in the specified
table. In order for iASP_Grid to work, the identity column must
be the first field specified in the main SELECT statement's list of fields.Due
to Grid.Cols(1).Hidden = True the first column of the grid i.e. id is
not visible. Column numbering is according to the order in the SELECT
statement. The method Cols(i) returns a corresponding Column
object representing a single column in the grid.
Grid.Display does most of the component's work. It carries out
all user requests such as Add New or Save, by opening the recordset, reading
data from the table, and generating the actual Table or Form requested.
Grid.Disconnect terminates the connection to the datasource established
through Grid.Connect.
Additional samples
The following samples demonstrate step by step how to build powerful
iASP_Grid based Web applications.
If you require technical support please send complete details about the
problem you are having to support@halcyonsoft.com.
|