Sample4.asp
| <HTML>
<frameset cols="300,*" frameborder=1 border=1 framepadding=5 framespacing=0> <frame src="Sample4Left.asp" name="LeftFrame" marginwidth=5 marginheight=5 scrolling=auto nowrap target="RightFrame"> <frame src="Sample4Right.asp" name="RightFrame" marginwidth=0 marginheight=0 scrolling=yes> </frameset> </HTML> |
Sample4Left.asp
| <%
Set LeftGrid = Server.CreateObject("Persits.AspGrid.1") LeftGrid.FileName = "Sample4Left.asp" LeftGrid.Connect "AspGrid", "", "" LeftGrid.SQL = "select '<A HREF=Sample4Right.asp?id=' + CStr(id) + '>' + name + '</A>' from Departments" LeftGrid.CanAppend = False LeftGrid.CanEdit = False LeftGrid.CanDelete = False LeftGrid.Table.Border = 0 LeftGrid.ShowHeader = False %> <HTML>
|
Sample4Right.asp
| <%
Set RightGrid = Server.CreateObject("Persits.AspGrid.1") RightGrid.FileName = "Sample4Right.asp" RightGrid.Connect "AspGrid", "", "" RightGrid.SQL = "select id, DepartmentID, FirstName, LastName, Salary, MaritalStatus, FullyVested from Employee where DepartmentID = " & Request("id") RightGrid.ColRange(1, 2).Hidden = True RightGrid.Cols(2).DefaultValue = Request("id") RightGrid.Cols(5).FormatNumeric 2, True RightGrid.Cols(5).Cell.Align = "RIGHT" RightGrid.Cols(6).Array = Array("Single", "Married", "Divorced") RightGrid.Cols(6).VArray = Array(1, 2, 3) RightGrid.Cols(7).AttachCheckBox "Yes", "No" RightGrid.ExtraFormItems = "<INPUT TYPE=HIDDEN NAME=ID VALUE=" & Request("id") & ">" %> <HTML>
|
Let's look at the file Sample4Left.asp line by line:
The line
LeftGrid.SQL = "select '<A HREF=Sample4Right.asp?id=' + CStr(id) + '>' + name + '</A>' from Departments"
contains a rather unusual SQL statement. This is the way to "trick" AspGrid into displaying a column as a hyper link rather than plain text. The MS Access CStr function is used to convert an integer ID to a string so that we can build an HREF attribute. In SQL Server you would need to use the Convert function.
The same idea can be used to make AspGrid display images.
These three lines
LeftGrid.CanAppend
= False
LeftGrid.CanEdit
= False
LeftGrid.CanDelete
= False
simply hide Add New, Edit and Delete control buttons, respectively, effectively rendering the grid non-editable.
These two lines
LeftGrid.Table.Border
= 0
LeftGrid.ShowHeader
= False
set the BORDER attribute of
our <TABLE> to 0 and hide the
table header. This way we complete our goal of making the grid visually
undetectable.
We will now turn out attention to Sample4Right.asp:
RightGrid.SQL = "select id, DepartmentID, FirstName, LastName, Salary, MaritalStatus, FullyVested from Employee where DepartmentID = " & Request("id")
Unlike the SQL statements in the previous lessons, this one has a WHERE clause. Our right-side grid should only display employees working in a department which ID was passed via Request.QueryString("id") from the left frame (for the sake of simplicity we say Request("id")).
RightGrid.ColRange(1,
2).Hidden = True
RightGrid.Cols(2).DefaultValue
= Request("id")
In this example we hide both the identity column (as we did before) and the department id column since the user already knows which department all the employees belong to. But we do need to make sure that new employees entered will be assigned to the right department. That's why we set the default value for column 2 to the department ID passed from the left frame.
RightGrid.ExtraFormItems = "<INPUT TYPE=HIDDEN NAME=ID VALUE=" & Request("id") & ">"
This line ensures the persistence of the Request.QueryString("ID") variable within the right frame. An ExtraFormItems property value will be added to every HTML FORM generated by AspGrid. If we failed to set this property, Request.QueryString("ID") would be empty the very first time we clicked on a button in the right-side grid, so we wouldn't be able to modify the employee information in the right frame.
RightGrid.Cols(7).AttachCheckBox "Yes", "No"
The field Employee.FullyVested can only assume two values, True
and False (1 and 0), so it is a good candidate to be displayed using the
check box control. The AttachCheckBox method will force the column
to be displayed as a check box while in the edit mode. The first and second
arguments of the method specify what should be displayed for a non-zero
and zero values, respectively, while in the non-edit mode. In our example,
we simply set the arguments to to the strings "Yes" and "No". We could
instead specify two <IMG> tags
so that AspGrid would display appropriate image icons.