Here is what the browser will show:
This looks like our empty Departments table. Let's now click on the "plus" sign:
Go ahead and enter some data for our first department record. Once you are done, click on the "ok" button:
Congratulations! You have just entered your first record into the Departments table. Now click on the "pencil" button. This will activate the in-place editing mode for this record.
You can now edit this record's data. Once you are done, click "ok" if you want to save the changes, or "cancel" otherwise.
| <%
Set Grid = Server.CreateObject("Persits.AspGrid.1") Grid.FileName = "Sample1.asp" Grid.Connect "AspGrid", "", "" Grid.SQL = "select id, name, phone from Departments" Grid.Cols(1).Hidden = True %> <HTML>
<% Grid.Display %>
</BODY>
|
Let's examine the file line by line.
The line Set Grid = Server.CreateObject("Persits.AspGrid.1") simply creates an instance of the AspGrid object.
The line Grid.FileName = "Sample1.asp" specifies this script's file name. AspGrid will use this property to correctly generate the ACTION attributes of all FORMs.
The line Grid.Connect "AspGrid", "", "" specifies an ODBC datasource name (DSN), user id and password. In our case the DSN is "AspGrid". Since we don't use security in our sample database, the user id and password are left blank.
The line Grid.SQL
= "select id, name, phone from Departments" specifies
the SQL SELECT statement that our grid will be based on. It contains all
three fields of the table even though we only see two of them, name
and phone.
Embedded in the HTML body is the main "workhorse" method Grid.Display. This method does most of the component's work: it handles user commands such as Add New or Save by reading the Request.QueryString collection, opens the recordset, reads data from the table, generates grid HTML and sends it out via a series of Response.Write calls.
And finally we call Grid.Disconnect
to terminate the connection to our datasource begun by Grid.Connect.