HOWTO: Populating a FlexGrid Control with ADO and ASPID: Q189406
|
The FlexGrid ActiveX control is a powerful control to display and manipulate data from a database in Internet Explorer. This sample uses Visual InterDev's DataCommand Design-time control to access the datasource. The client-side script uses a call to a subroutine to actually build the HTML source code that will add rows and columns to the FlexGrid control before the control is displayed by Internet Explorer.
To use the Flexgrid ActiveX control in a new .asp script follow these
steps:
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
<!--METADATA TYPE="DesignerControl" startspan
<OBJECT ID="objRst" WIDTH=383 HEIGHT=24
CLASSID="CLSID:7FAEED80-9D58-11CF-8F68-00AA006D27C2">
<PARAM NAME="_Version" VALUE="65536">
<PARAM NAME="_Version" VALUE="65536">
<PARAM NAME="_ExtentX" VALUE="10125">
<PARAM NAME="_ExtentY" VALUE="635">
<PARAM NAME="_StockProps" VALUE="0">
<PARAM NAME="DataConnection" VALUE="MagisterPubs">
<PARAM NAME="CommandText" VALUE="SELECT authors.* FROM authors">
<PARAM NAME="CursorType" VALUE="3">
</OBJECT>
-->
<%
Set MagisterPubs = Server.CreateObject("ADODB.Connection")
MagisterPubs.ConnectionTimeout =
Session("MagisterPubs_ConnectionTimeout")
MagisterPubs.CommandTimeout = Session("MagisterPubs_CommandTimeout")
MagisterPubs.Open Session("MagisterPubs_ConnectionString"),
Session("MagisterPubs_RuntimeUserName"),
Session("MagisterPubs_RuntimePassword")
Set cmdTemp = Server.CreateObject("ADODB.Command")
Set objRst = Server.CreateObject("ADODB.Recordset")
cmdTemp.CommandText = "SELECT authors.* FROM authors"
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = MagisterPubs
objRst.Open cmdTemp, , 3, 1
%>
<!--METADATA TYPE="DesignerControl" endspan-->
<%
Sub FillCells
Dim ctRow, ctCol, vbCrLF
vbCrLf= Chr(13) & Chr(10)
ctCol=0
' Note: added 1 to rows so that we can print field headings
Response.Write "MSFlexGrid1.Rows=" & objRst.RecordCount+1 & vbCrLf
Response.Write "MSFlexGrid1.Cols=" & objRst.Fields.Count & vbCrLf
' Print field headings
Response.Write "MSFlexGrid1.Row=0" & vbCrLf
For Each fld in objRst.Fields
Response.Write "MSFlexGrid1.Col=" & ctCol & vbCrLf
Response.Write "MSFlexGrid1.Text=" & Chr(34) & Trim(fld.Name) &
Chr(34) & vbCrLf
ctCol=ctCol+1
Next
' Print data
ctRow=1
Do Until objRst.eof
Response.Write "MSFlexGrid1.Row=" & ctRow & vbCrLf
ctCol=0
For Each fld in objRst.Fields
Response.Write "MSFlexGrid1.Col=" & ctCol & vbCrLf
Response.Write "MSFlexGrid1.Text=" & Chr(34) & Trim(fld) &
Chr(34) & vbCrLf
ctCol=ctCol+1
Next
objRst.MoveNext
ctRow=ctRow+1
Loop
End Sub
%>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub window_onLoad()
<%FillCells%>
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<OBJECT ID="MSFlexGrid1" WIDTH=668 HEIGHT=156
CLASSID="CLSID:6262D3A0-531B-11CF-91F6-C2863C385E30">
<PARAM NAME="_ExtentX" VALUE="17674">
<PARAM NAME="_ExtentY" VALUE="4128">
<PARAM NAME="_Version" VALUE="65541">
<PARAM NAME="Rows" VALUE="2">
<PARAM NAME="Cols" VALUE="1">
<PARAM NAME="FixedRows" VALUE="1">
<PARAM NAME="FixedCols" VALUE="0">
<PARAM NAME="AllowUserResizing" VALUE="1">
</OBJECT>
</BODY>
</HTML>
Additional query words: FlexGrid ActiveX control ADO CursorType window_onload client-side server-side script
Keywords : kbActiveX kbADO kbASP kbScript kbVBp kbVBScript kbGrpASP
Version : WINDOWS:1.0; winnt:
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: May 27, 1999