Sample 3: | Continue To Sample 4 Back To Samples |
Click here
>> Run Sample 3 Note: If you haven't configured your Microsoft Access driver, please click here. |
This sample is in the form of Frames. The right Frame displays the Sample3Right.asp page and the left Frame displays the Sample3Left.asp page.
In this sample, iASP_Grid is in frame environment, but in the table mode. Clicking on a department name in the left frame displays the employees of that department only. If a new employee is added, then it will automatically be assigned the department currently selected by the user.
Sample Code:Sample3.asp
<HTML>
<frameset cols="300,*" frameborder=1 border=1 framepadding=5 framespacing=0>
<frame src="Sample3Left.asp" name="LeftFrame" marginwidth=5 marginheight=5 scrolling=auto nowrap target="RightFrame">
<frame src="Sample3Right.asp" name="RightFrame" marginwidth=0 marginheight=0 scrolling=yes>
</frameset>
</HTML>Sample4Left.asp
<%
Set LeftGrid = Server.CreateObject("Persits.AspGrid")
LeftGrid.FileName = "Sample3Left.asp"
LeftGrid.Connect "sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:Odbc:GridTest", "", ""
LeftGrid.SQL = "select '<A HREF=Sample3Right.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>
<BODY>
<BASE TARGET="RightFrame">
<H3>Departments:</H3>
<% LeftGrid.Display %>
<% LeftGrid.Disconnect %>
</BODY>
</HTML>
Sample4Right.asp
<%Set RightGrid = Server.CreateObject("Persits.AspGrid")
RightGrid.FileName = "Sample3Right.asp"
RightGrid.Connect "sun.jdbc.odbc.JdbcOdbcDriver", "jdbc:Odbc:GridTest", "", ""
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>
<BODY>
<H3>Employees:</H3><%
If Request("ID") <> "" Then
RightGrid.Display
RightGrid.Disconnect
End If%>
</BODY>
</HTML>
Description:
The first five steps for creating a Grid Object have already been discussed. See the main page of samples for details.
LeftGrid.SQL = "select '<A
HREF=Sample4Right.asp?id=' + CStr(id) + '>' + name + '</A>' from Departments"
The above line displays a column
as a hyper link rather than plain text. The Microsoft AccessTM
CStr
function is used to convert an integer ID to a string so that an HREF attribute
can be built.
The CStr function is specific to Microsoft AccessTM , therefore this Sample might not work as described with other databases.
LeftGrid.CanAppend = False
Hides the Add New button
of the grid.
LeftGrid.CanEdit = False
Hides the Edit button of
the grid.
LeftGrid.CanDelete = False
Hides the Delete button of
the grid.
LeftGrid.Table.Border = 0
Sets the BORDER attribute of the
<TABLE> tag to 0
LeftGrid.ShowHeader = False
Hides the table header.
Consider the following coding for Sample4Right.asp :
RightGrid.SQL = "select id, DepartmentID,
FirstName, LastName, Salary, MaritalStatus, FullyVested from Employee where
DepartmentID = " & Request("id")
The right-side grid only displays
employees working in a department. The ID of that department is passed
via Request.("id") from the left frame.
RightGrid.ColRange(1, 2).Hidden
= True
This line instructs iASP_Grid to
hide column 1 and Column 2 of the grid.
RightGrid.Cols(2).DefaultValue
= Request("id")
In this example the default value
is set for column 2 to the department ID passed from the left frame.
RightGrid.ExtraFormItems = "<INPUT
TYPE=HIDDEN NAME=ID VALUE=" & Request("id") & ">"
The String specified for ExtraFormItems
property will be added to every HTML FORM generated by iASP_Grid.
The above line generates a hidden Text Field in every <HTML> form and
sets the value of that text field to the Request("id"). This
way the ID passed from the left frame to the right remains persistent throughout
the operations being performed on the right side grid. In case this fails,
the user won't be able to modify the employee information displayed in
the right side grid.
RightGrid.Cols(7).AttachCheckBox
"Yes", "No"
In the database the Employee.FullyVested
field is specified as Yes/No type i.e. it can only assume two values (1
and 0). While in the Edit or Add mode, the AttachCheckBox
method will displayed the column as a check box. The first argument
specifies the value that will be displayed for that column in the Non- Edit/Add
mode for a non-zero value (True). The second argument specifies the
value that will be displayed for that column in the Non- Edit/Add mode
for a zero value (False).
Click here >> Run Sample 3 | |
Back to Top | Continue To Sample 4 Back To Samples |
If you require technical support please send complete details about the problem you are having to support@halcyonsoft.com.
Copyright 1998-2000, Halcyon
Software Inc. All rights reserved.